package model

import (
	"time"

	"github.com/tech/sendico/pkg/db/storable"
	"github.com/tech/sendico/pkg/model"
)

// JournalEntry represents an atomic ledger transaction with multiple posting lines.
type JournalEntry struct {
	storable.Base               `bson:",inline" json:",inline"`
	model.OrganizationBoundBase `bson:",inline" json:",inline"`

	IdempotencyKey string            `bson:"idempotencyKey" json:"idempotencyKey"` // unique key for deduplication
	EventTime      time.Time         `bson:"eventTime" json:"eventTime"`           // business event timestamp
	EntryType      EntryType         `bson:"entryType" json:"entryType"`           // credit, debit, transfer, fx, fee, adjust, reverse
	Description    string            `bson:"description" json:"description"`
	Metadata       map[string]string `bson:"metadata,omitempty" json:"metadata,omitempty"`
	Version        int64             `bson:"version" json:"version"` // for ordering and optimistic locking
}

// Collection implements storable.Storable.
func (*JournalEntry) Collection() string {
	return JournalEntriesCollection
}
