package models

import "time"

//////////////////////////////////////////////////////////////
// Astrology Service Catalogue and Usage
//////////////////////////////////////////////////////////////

// AstrologyService is one row of the admin panel's service catalogue
// (astrology_services). The admin panel owns it; this API only reads the
// switches it enforces. Code is the stable key and never changes.
type AstrologyService struct {
	ID                uint   `gorm:"column:id;primaryKey" json:"id"`
	Code              string `gorm:"column:code" json:"code"`
	Family            string `gorm:"column:family" json:"family"`
	Name              string `gorm:"column:name" json:"name"`
	Provider          string `gorm:"column:provider" json:"provider"`
	CustomerEnabled   bool   `gorm:"column:customer_enabled" json:"customer_enabled"`
	AstrologerEnabled bool   `gorm:"column:astrologer_enabled" json:"astrologer_enabled"`
	AccessMode        string  `gorm:"column:access_mode" json:"access_mode"`
	Price             float64 `gorm:"column:price" json:"price"`
	FreeQuota         int     `gorm:"column:free_quota" json:"free_quota"`
	QuotaPeriod       string  `gorm:"column:quota_period" json:"quota_period"`
	RequiresLogin     bool    `gorm:"column:requires_login" json:"requires_login"`
	IsActive          bool    `gorm:"column:isActive" json:"isActive"`
}

func (AstrologyService) TableName() string {
	return "astrology_services"
}

// AstrologyServiceUsage is one astrology service call, for the admin panel's
// Service Usage report. This API is the only writer. platform, device_type and
// app_version come from migrations/2026_09_25_astrology_service_usage_platform.sql.
type AstrologyServiceUsage struct {
	ID            uint64    `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	ServiceID     uint      `gorm:"column:service_id" json:"service_id"`
	ServiceCode   string    `gorm:"column:service_code" json:"service_code"`
	UserID        *uint     `gorm:"column:user_id" json:"user_id"`
	AstrologerID  *uint     `gorm:"column:astrologer_id" json:"astrologer_id"`
	ActorType     string    `gorm:"column:actor_type" json:"actor_type"`
	Platform      *string   `gorm:"column:platform" json:"platform"`
	DeviceType    *string   `gorm:"column:device_type" json:"device_type"`
	AppVersion    *string   `gorm:"column:app_version" json:"app_version"`
	Provider      *string   `gorm:"column:provider" json:"provider"`
	WasFree       bool      `gorm:"column:was_free" json:"was_free"`
	ChargedAmount float64   `gorm:"column:charged_amount" json:"charged_amount"`
	WasCached     bool      `gorm:"column:was_cached" json:"was_cached"`
	Succeeded     bool      `gorm:"column:succeeded" json:"succeeded"`
	FailureReason *string   `gorm:"column:failure_reason" json:"failure_reason"`
	ResponseMs    *int64    `gorm:"column:response_ms" json:"response_ms"`
	CreatedAt     time.Time `gorm:"column:created_at" json:"created_at"`
}

func (AstrologyServiceUsage) TableName() string {
	return "astrology_service_usage"
}
