package galon

import (
	"context"
)

// GalonJournalFn posts the accounting journal for one completed galon
// transaction. Implemented in cmd/server via the accounting service (the same
// pattern as inventory's OpnameAdjustmentJournal and purchasing's
// WithAccounting) — galon must not import accounting directly.
//
// amount is the item revenue (quantity × unit price). depositAmount is the
// customer money held — a LIABILITY, never revenue, and it gets its own line
// pair so a report can state both at once. Either amount may be zero; the
// implementation decides which lines to write (a refill with no deposit has
// no deposit lines to book).
type GalonJournalFn func(ctx context.Context, in GalonJournalInput) (journalNumber string, err error)

// GalonJournalInput carries everything the journal needs, so the
// implementation stays free of galon storage types.
type GalonJournalInput struct {
	TransactionNumber string
	// Type: refill | buy_galon_plus_contents | borrow_galon.
	Type    string
	CashAcc string
	// Revenue = quantity × unit price (0 for a pure loan).
	Revenue        float64
	DepositAmount  float64
	RevenueAccount string // e.g. 4000.02 Pendapatan Depot Galon Air
	DepositAccount string // e.g. 2000.02 Uang Muka Penjualan / Deposit Customer
}

// WithJournal wires the accounting hook. Nil keeps the pre-journal behavior:
// payments exist, the ledger does not see galon.
func (s *Service) WithJournal(fn GalonJournalFn) *Service {
	s.journalFn = fn
	return s
}
