package entity

import (
	"time"

	"github.com/shopspring/decimal"
	"github.com/tidbcloud/serverless-service/internal/domain/constant"
)

type Cluster struct {
	ID                   uint64          `gorm:"primary_key;not null"`
	KeyspaceID           uint64          `gorm:"index;not null"`
	TenantID             uint64          `gorm:"not null"`
	ProjectID            uint64          `gorm:"index;not null"`
	CloudProviderName    string          `gorm:"not null"`
	RegionName           string          `gorm:"index;not null"`
	CreatedTime          time.Time       `gorm:"type:TIMESTAMP;not null"`
	CreationFinishedTime *time.Time      `gorm:"type:TIMESTAMP;"`
	SpendLimit           decimal.Decimal `gorm:"type:decimal(20,2);not null"`
	FreeCredit           decimal.Decimal `gorm:"type:decimal(20,2);not null"`
	IsPaid               bool            `gorm:"not null"`
	CanaryMark           bool            `gorm:"index:not null"`
	UpdatedAt            *time.Time      `gorm:"updated_at;type:TIMESTAMP"`

	RuMode constant.ClusterRUMode `gorm:"type:ENUM('standard','throttled');not null"`
}

type ClusterTidbPool struct {
	EventID          uint64     `gorm:"primary_key;not null"`
	Type             string     `gorm:"type:ENUM('spend_limit','canary');not null"`
	ClusterID        uint64     `gorm:"index;not null"`
	ProjectID        uint64     `gorm:""`
	CreatedAt        time.Time  `gorm:"created_at;type:TIMESTAMP;not null;<-:create"`
	UpdatedAt        *time.Time `gorm:"updated_at;type:TIMESTAMP"`
	SpendLimitStatus string     `gorm:""`
	CanaryMark       bool       `gorm:""`
	Status           string     `gorm:"type:ENUM('synced','unsynced');not null"`
	PoolName         string     `gorm:""`
	RuLimitMode      string     `gorm:""`
}

type Downtime struct {
	ClusterID   string          `gorm:"primaryKey;not null"`
	DownTime    time.Time       `gorm:"primaryKey;type:TIMESTAMP;not null"`
	DownRate    decimal.Decimal `gorm:"type:decimal(20,2);not null"`
	Connections decimal.Decimal `gorm:"type:decimal(20,0);not null"`
	Region      string          `gorm:"not null"`
	Month       string          `gorm:"index:idx_month;index:idx_pool_month;not null"`
	TidbPool    string          `gorm:"index:idx_pool_month;not null"`
	UpdatedAt   time.Time       `gorm:"type:TIMESTAMP;not null"`
}
