package dto_astrologer

// The astrologer app's view of its own earnings, and where each rupee is in
// the settlement lifecycle:
//
//	PENDING        the session was billed to the customer; the admin has not
//	               reviewed it yet
//	TO_BE_SETTLED  reviewed and released, waiting for the settlement job
//	SETTLED        credited to the wallet — this is the money that can be
//	               withdrawn
//
// Nothing below is withdrawable except what has already reached the wallet.
// That is deliberate: the withdraw screen reads the wallet balance, so an
// unsettled earning can never be paid out early.

//------------------------------------------------
// Settlement history (batches)
//------------------------------------------------

// SettlementHistoryItem is one settlement batch — one run, for this
// astrologer, closing however many consultations had been released.
type SettlementHistoryItem struct {
	ID           uint   `json:"id"`
	SettlementNo string `json:"settlementNo"`

	// What was credited to the wallet.
	Amount float64 `json:"amount"`

	// The gross the customers paid and the platform's cut of it, so the
	// astrologer can see how the credited amount was arrived at.
	GrossAmount float64 `json:"grossAmount"`
	PlatformFee float64 `json:"platformFee"`

	ConsultationCount int `json:"consultationCount"`

	Status string `json:"status"`

	// The window the batch covered, e.g. "01 Sep 2026" to "07 Sep 2026".
	PeriodFrom string `json:"periodFrom,omitempty"`
	PeriodTo   string `json:"periodTo,omitempty"`

	Remarks string `json:"remarks,omitempty"`

	SettlementDate string `json:"settlementDate,omitempty"`
	CreatedAt      string `json:"createdAt"`
}

type SettlementHistoryResponse struct {
	Items []SettlementHistoryItem `json:"items"`

	Page       int   `json:"page"`
	Limit      int   `json:"limit"`
	Total      int64 `json:"total"`
	TotalPages int   `json:"totalPages"`

	// Everything ever credited through settlements, not just this page.
	TotalSettled float64 `json:"totalSettled"`
}

//------------------------------------------------
// Consultation rows
//------------------------------------------------

// SettlementConsultationItem is one session inside a batch, or one session
// still waiting to be settled.
type SettlementConsultationItem struct {
	ConsultationID uint   `json:"consultationId"`
	ConsultationNo string `json:"consultationNo"`

	Medium string `json:"medium"`

	Duration      string  `json:"duration"`
	BilledMinutes int     `json:"billedMinutes"`
	RatePerMinute float64 `json:"ratePerMinute"`

	// What the customer paid, the platform's cut, and what is owed to or paid
	// to the astrologer.
	GrossAmount       float64 `json:"grossAmount"`
	PlatformFee       float64 `json:"platformFee"`
	AstrologerEarning float64 `json:"astrologerEarning"`

	SettlementStatus string `json:"settlementStatus"`

	// Friendly label for the app: "Awaiting review", "Approved", "Settled".
	StatusLabel string `json:"statusLabel"`

	// True when the platform funded the session rather than the customer. The
	// astrologer is still paid in full, which is why platformFee comes back
	// negative on these rows — it is a subsidy, not a commission. Worth
	// labelling in the app so a ₹0 grossAmount does not read as unpaid work.
	IsFreeChat  bool `json:"isFreeChat"`
	FreeMinutes int  `json:"freeMinutes,omitempty"`

	ConsultationDate string `json:"consultationDate"`
	SettledAt        string `json:"settledAt,omitempty"`
}

// SettlementBatchDetailResponse is a batch opened up.
type SettlementBatchDetailResponse struct {
	SettlementHistoryItem

	Consultations []SettlementConsultationItem `json:"consultations"`
}

//------------------------------------------------
// Upcoming
//------------------------------------------------

// UpcomingSettlementResponse is the "what am I owed" screen: everything
// billed to a customer that has not reached the wallet yet.
type UpcomingSettlementResponse struct {
	// Billed, not yet reviewed by an admin.
	PendingCount  int     `json:"pendingCount"`
	PendingAmount float64 `json:"pendingAmount"`

	// Reviewed and released; the next settlement run will credit these.
	ToBeSettledCount  int     `json:"toBeSettledCount"`
	ToBeSettledAmount float64 `json:"toBeSettledAmount"`

	// Parked by the admin, usually pending a dispute.
	OnHoldCount  int     `json:"onHoldCount"`
	OnHoldAmount float64 `json:"onHoldAmount"`

	// PendingAmount + ToBeSettledAmount: what is still on its way.
	TotalUnsettled float64 `json:"totalUnsettled"`

	// When the settlement job is next due, as configured by the admin. Empty
	// when the schedule is a custom cron expression this API does not parse.
	NextSettlementAt string `json:"nextSettlementAt,omitempty"`

	Consultations []SettlementConsultationItem `json:"consultations"`
}

//////////////////////////////////////////////////////////////
// Consultation earnings
//////////////////////////////////////////////////////////////

// ConsultationEarningsResponse is every billed session and where its money has
// got to, whatever its settlement status.
//
// This is the screen that works from the first consultation. settlement/history
// lists credited BATCHES, so it is empty — correctly — until an admin has
// approved sessions and the settlement job has run, which can be days after
// the astrologer's first chat.
type ConsultationEarningsResponse struct {
	Items []SettlementConsultationItem `json:"items"`

	Page       int   `json:"page"`
	Limit      int   `json:"limit"`
	Total      int64 `json:"total"`
	TotalPages int   `json:"totalPages"`

	// Across every row matching the filter, not just this page.
	PendingAmount     float64 `json:"pendingAmount"`
	ToBeSettledAmount float64 `json:"toBeSettledAmount"`
	OnHoldAmount      float64 `json:"onHoldAmount"`
	SettledAmount     float64 `json:"settledAmount"`
	TotalEarning      float64 `json:"totalEarning"`
}
