package dto_admin

// The admin general settings screen, as far as the finance flow is concerned.
//
// Everything here lives in `systemflag`, which is the single source of truth
// both this API and the admin panel's scheduler read. The API never schedules
// anything itself — it stores the schedule and derives the cron expression the
// scheduler runs on.

//------------------------------------------------
// Read
//------------------------------------------------

type GeneralSettingsResponse struct {
	//------------------------------------------------
	// Consultation billing
	//------------------------------------------------

	// The platform's cut of every consultation, applied when a session is
	// billed. Changing it affects future sessions only: the percent that was
	// in force is stored on each consultation row.
	PlatformCommissionPercent float64 `json:"platform_commission_percent"`

	// Balance, in minutes of the astrologer's rate, a customer must hold
	// before a session can start.
	MinConsultationMinutes float64 `json:"min_consultation_minutes"`

	// Sessions shorter than this are not billed, so a call that never really
	// connected is free.
	ConsultationGraceSeconds float64 `json:"consultation_grace_seconds"`

	// How long a session may go without a balance tick before the sweeper
	// closes and bills it.
	ConsultationTickTimeoutSecs float64 `json:"consultation_tick_timeout_secs"`

	//------------------------------------------------
	// Settlement schedule
	//------------------------------------------------

	// WEEKLY, MONTHLY or CUSTOM.
	SettlementFrequency string `json:"settlement_frequency"`

	// 0 = Sunday .. 6 = Saturday. Used by WEEKLY.
	SettlementDayOfWeek int `json:"settlement_day_of_week"`

	// 1-28. Used by MONTHLY.
	SettlementDayOfMonth int `json:"settlement_day_of_month"`

	// HH:MM, 24h. Used by WEEKLY and MONTHLY.
	SettlementRunTime string `json:"settlement_run_time"`

	// The expression the admin panel's scheduler runs on. Derived from the
	// three fields above for WEEKLY and MONTHLY; typed by the admin for
	// CUSTOM.
	SettlementCronExpression string `json:"settlement_cron_expression"`

	// Plain-English rendering of the schedule for the settings screen.
	ScheduleDescription string `json:"schedule_description"`

	// When the schedule next fires. Empty for CUSTOM, because this API does
	// not parse cron expressions — the scheduler owns that.
	NextRunAt string `json:"next_run_at,omitempty"`

	//------------------------------------------------
	// Settlement rules
	//------------------------------------------------

	// When true the job also settles PENDING consultations no admin has
	// reviewed. Off by default: nothing should be credited without a review.
	SettlementAutoApprove bool `json:"settlement_auto_approve"`

	// A batch below this amount rolls into the next run. 0 settles
	// everything.
	SettlementMinPayout float64 `json:"settlement_min_payout"`
}

//------------------------------------------------
// Write
//------------------------------------------------

// UpdateGeneralSettingsRequest is a partial update: every field is a pointer,
// so the settings screen can save one field without having to send — and
// risk overwriting — all the others.
type UpdateGeneralSettingsRequest struct {
	PlatformCommissionPercent *float64 `json:"platform_commission_percent"`
	MinConsultationMinutes    *float64 `json:"min_consultation_minutes"`
	ConsultationGraceSeconds  *float64 `json:"consultation_grace_seconds"`
	ConsultationTickTimeoutSecs *float64 `json:"consultation_tick_timeout_secs"`

	SettlementFrequency  *string `json:"settlement_frequency"`
	SettlementDayOfWeek  *int    `json:"settlement_day_of_week"`
	SettlementDayOfMonth *int    `json:"settlement_day_of_month"`
	SettlementRunTime    *string `json:"settlement_run_time"`

	// Only honoured when the frequency is CUSTOM. For WEEKLY and MONTHLY the
	// expression is derived, and a value sent here is ignored rather than
	// silently disagreeing with the parts.
	SettlementCronExpression *string `json:"settlement_cron_expression"`

	SettlementAutoApprove *bool    `json:"settlement_auto_approve"`
	SettlementMinPayout   *float64 `json:"settlement_min_payout"`
}
