package models

import "time"

// WalletSettlement carries two opposite money movements, told apart by
// SettlementType:
//
//	CONSULTATION_BATCH  the settlement job credited a batch of reviewed
//	                    consultations into the astrologer wallet (money in)
//	WITHDRAW_PAYOUT     a withdrawal was paid out of the wallet (money out)
//
// The batch columns come from migrations/2026_09_15_settlement_schedule.sql.
type WalletSettlement struct {
	ID                uint       `gorm:"primaryKey;autoIncrement" json:"id"`
	UserID            uint       `gorm:"column:user_id" json:"user_id"`
	AstrologerID      uint       `gorm:"column:astrologer_id" json:"astrologer_id"`
	WithdrawRequestID uint       `gorm:"column:withdraw_request_id"`
	SettlementNo      string     `gorm:"column:settlement_no"`
	SettlementType    string     `gorm:"column:settlement_type"`
	Amount            float64    `gorm:"column:amount"`
	SettlementStatus  string     `gorm:"column:settlement_status"`
	PaymentMode       string     `gorm:"column:payment_mode"`
	PaymentReference  string     `gorm:"column:payment_reference"`
	SettlementDate    *time.Time `gorm:"column:settlement_date"`
	Remarks           string     `gorm:"column:remarks"`

	// Batch columns. Zero on a withdraw payout, which closes no
	// consultations.
	ConsultationCount int        `gorm:"column:consultation_count"`
	PeriodFrom        *time.Time `gorm:"column:period_from"`
	PeriodTo          *time.Time `gorm:"column:period_to"`
	GrossAmount       float64    `gorm:"column:gross_amount"`
	PlatformFee       float64    `gorm:"column:platform_fee"`

	// Admin user id, or 0 when the scheduler called the run endpoint with the
	// admin API key.
	ProcessedBy uint `gorm:"column:processed_by"`

	CreatedAt *time.Time `gorm:"column:created_at;autoCreateTime" json:"createdAt"`
	UpdatedAt *time.Time `gorm:"column:updated_at;autoUpdateTime" json:"updatedAt"`
}

func (WalletSettlement) TableName() string {
	return "wallet_settlements"
}
