package models

import "time"

type Consultation struct {
	ID             uint   `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	ConsultationNo string `gorm:"column:consultationNo" json:"consultationNo"`

	UserID       uint `gorm:"column:userId" json:"userId"`
	AstrologerID uint `gorm:"column:astrologerId" json:"astrologerId"`

	Medium             string     `gorm:"column:medium" json:"medium"`
	Status             string     `gorm:"column:status" json:"status"`
	EndReason          string     `gorm:"column:endReason" json:"endReason"`
	ChannelName        string     `gorm:"column:channelName" json:"channelName"`
	RatePerMinute      float64    `gorm:"column:ratePerMinute" json:"ratePerMinute"`
	FreeMinutes        int        `gorm:"column:freeMinutes" json:"freeMinutes"`
	FreeSeconds        int        `gorm:"column:freeSeconds" json:"freeSeconds"`
	RequestedAt        *time.Time `gorm:"column:requestedAt" json:"requestedAt,omitempty"`
	AcceptedAt         *time.Time `gorm:"column:acceptedAt" json:"acceptedAt,omitempty"`
	StartedAt          *time.Time `gorm:"column:startedAt" json:"startedAt,omitempty"`
	EndedAt            *time.Time `gorm:"column:endedAt" json:"endedAt,omitempty"`
	LastTickAt         *time.Time `gorm:"column:lastTickAt" json:"lastTickAt,omitempty"`
	WarnedAt           *time.Time `gorm:"column:warnedAt" json:"warnedAt,omitempty"`
	MaxBillableSeconds int        `gorm:"column:maxBillableSeconds" json:"maxBillableSeconds"`
	DurationSeconds    int        `gorm:"column:durationSeconds" json:"durationSeconds"`
	BilledSeconds      int        `gorm:"column:billedSeconds" json:"billedSeconds"`
	BilledMinutes      int        `gorm:"column:billedMinutes" json:"billedMinutes"`
	GrossAmount        float64    `gorm:"column:grossAmount" json:"grossAmount"`
	PlatformFeePercent float64    `gorm:"column:platformFeePercent" json:"platformFeePercent"`
	PlatformFeeAmount  float64    `gorm:"column:platformFeeAmount" json:"platformFeeAmount"`
	AstrologerEarning  float64    `gorm:"column:astrologerEarning" json:"astrologerEarning"`
	SettlementStatus   string     `gorm:"column:settlementStatus" json:"settlementStatus"`
	SettlementID       *uint      `gorm:"column:settlementId" json:"settlementId,omitempty"`
	SettledAt          *time.Time `gorm:"column:settledAt" json:"settledAt,omitempty"`
	AdminRemarks       string     `gorm:"column:adminRemarks" json:"adminRemarks"`
	AdminActionBy      *uint      `gorm:"column:adminActionBy" json:"adminActionBy,omitempty"`
	AdminActionAt      *time.Time `gorm:"column:adminActionAt" json:"adminActionAt,omitempty"`
	Name               string     `gorm:"column:name" json:"name"`
	BirthDate          *time.Time `gorm:"column:birthDate" json:"birthDate,omitempty"`
	BirthTime          string     `gorm:"column:birthTime" json:"birthTime"`
	BirthPlace         string     `gorm:"column:birthPlace" json:"birthPlace"`
	Gender             string     `gorm:"column:gender" json:"gender"`
	ChatHistoryID      *uint      `gorm:"column:chatHistoryId" json:"chatHistoryId,omitempty"`
	CallHistoryID      *uint      `gorm:"column:callHistoryId" json:"callHistoryId,omitempty"`
	IsDelete           bool       `gorm:"column:isDelete" json:"isDelete"`
	CreatedAt          *time.Time `gorm:"column:created_at" json:"createdAt,omitempty"`
	UpdatedAt          *time.Time `gorm:"column:updated_at" json:"updatedAt,omitempty"`
}

func (Consultation) TableName() string {
	return "consultations"
}

// ConsultationSettlementLog is one settlement-status transition. The
// consultations row keeps only the latest admin action; this keeps the trail,
// including the transition the settlement job itself makes.
type ConsultationSettlementLog struct {
	ID             uint       `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	ConsultationID uint       `gorm:"column:consultationId" json:"consultationId"`
	FromStatus     string     `gorm:"column:fromStatus" json:"fromStatus"`
	ToStatus       string     `gorm:"column:toStatus" json:"toStatus"`
	Remarks        string     `gorm:"column:remarks" json:"remarks"`
	ActionBy       uint       `gorm:"column:actionBy" json:"actionBy"`
	ActionSource   string     `gorm:"column:actionSource" json:"actionSource"`
	SettlementID   *uint      `gorm:"column:settlementId" json:"settlementId,omitempty"`
	CreatedAt      *time.Time `gorm:"column:created_at" json:"createdAt,omitempty"`
}

func (ConsultationSettlementLog) TableName() string {
	return "consultation_settlement_logs"
}
