package model

import "github.com/tech/sendico/pkg/model"

// Collection names used by the ledger persistence layer.
const (
	AccountsCollection        = "ledger_accounts"
	JournalEntriesCollection  = "journal_entries"
	PostingLinesCollection    = "posting_lines"
	AccountBalancesCollection = "account_balances"
	OutboxCollection          = "outbox"
)

// AccountType defines the category of account (asset, liability, revenue, expense).
type AccountType string

const (
	AccountTypeAsset     AccountType = "asset"
	AccountTypeLiability AccountType = "liability"
	AccountTypeRevenue   AccountType = "revenue"
	AccountTypeExpense   AccountType = "expense"
)

// AccountStatus tracks the operational state of an account.
type AccountStatus string

const (
	AccountStatusActive AccountStatus = "active"
	AccountStatusFrozen AccountStatus = "frozen"
	AccountStatusClosed AccountStatus = "closed"
)

// EntryType categorizes journal entries by their business purpose.
type EntryType string

const (
	EntryTypeCredit   EntryType = "credit"
	EntryTypeDebit    EntryType = "debit"
	EntryTypeTransfer EntryType = "transfer"
	EntryTypeFX       EntryType = "fx"
	EntryTypeFee      EntryType = "fee"
	EntryTypeAdjust   EntryType = "adjust"
	EntryTypeReverse  EntryType = "reverse"
)

// LineType distinguishes the role of a posting line within a journal entry.
type LineType string

const (
	LineTypeMain     LineType = "main"
	LineTypeFee      LineType = "fee"
	LineTypeSpread   LineType = "spread"
	LineTypeReversal LineType = "reversal"
)

// OutboxStatus tracks the delivery state of an outbox event.
type OutboxStatus string

const (
	OutboxStatusPending OutboxStatus = "pending"
	OutboxStatusSent    OutboxStatus = "sent"
	OutboxStatusFailed  OutboxStatus = "failed"
)

// Money represents an exact decimal amount with its currency.
type Money struct {
	Currency string `bson:"currency" json:"currency"`
	Amount   string `bson:"amount" json:"amount"` // stored as string for exact decimal representation
}

// LedgerMeta carries organization-scoped metadata for ledger entities.
type LedgerMeta struct {
	model.OrganizationBoundBase `bson:",inline" json:",inline"`

	RequestRef     string `bson:"requestRef,omitempty" json:"requestRef,omitempty"`
	TraceRef       string `bson:"traceRef,omitempty" json:"traceRef,omitempty"`
	IdempotencyKey string `bson:"idempotencyKey,omitempty" json:"idempotencyKey,omitempty"`
}
