package remediationticket

import (
	"time"

	tntent "github.com/tidbcloud/devops/entity/tenant"
	"github.com/tidbcloud/devops/models/base"
)

type RemediationTicket struct {
	base.Updatable

	AssociatedIncidentId uint64 `gorm:"type:bigint(20) unsigned;not null"`
	CurrentPhase         string `gorm:"type:VARCHAR(255);not null"` // use this field instead
	Status               string `gorm:"type:VARCHAR(255);not null"`
	Applicant            string `gorm:"type:VARCHAR(255);not null"`
	CurrentResponsible   string `gorm:"type:VARCHAR(255);not null"`

	// Create Params
	BizRegion       *tntent.TenantRegion `gorm:"type:VARCHAR(255)"`
	CustomerName    *string              `gorm:"type:VARCHAR(255)"`
	ClusterType     string               `gorm:"type:VARCHAR(255)"`
	TenantID        *uint64              `gorm:"type:bigint(20) unsigned"`
	ClusterID       *uint64              `gorm:"type:bigint(20) unsigned"`
	InfoFromCreator string               `gorm:"type:VARCHAR(2000)"`
	Month           string               `gorm:"type:VARCHAR(20)"`

	// Region TSE Fields
	RootCauseFromGS string `gorm:"type:VARCHAR(2000)"`

	// Region SLA Owner Fields
	AccumulatedDownMinutes  *int   `gorm:"type:int"`
	MonthlyUptimePercentage string `gorm:"type:VARCHAR(255)"`
	RootCauseFromRDG        string `gorm:"type:VARCHAR(2000)"`
	AccidentReportLink      string `gorm:"type:VARCHAR(255)"`

	// Global Deal Desk Fields
	ClusterBilling    string `gorm:"type:VARCHAR(255)"`
	PredefinedPercent string `gorm:"type:VARCHAR(255)"`
	ExtraPercent      string `gorm:"type:VARCHAR(255)"`
	TotalCompensation string `gorm:"type:VARCHAR(255)"`

	// Deprecated fields, will be removed in the future
	Reason                 *string  `gorm:"type:VARCHAR(255)"`
	IsServerless           bool     `gorm:"type:tinyint(1)"`
	ReportLink             *string  `gorm:"type:VARCHAR(255)"`
	CalculatedCompensation *float64 `gorm:"type:float(4,2)"`
	OverflowPercentage     *float64 `gorm:"type:float(4,2)"`

	ApprovalID *base.ID `gorm:"index:idx_approval_id"`

	GeneratedDocURL *string `gorm:"type:VARCHAR(255)"`

	ClosedAt *time.Time `gorm:"type:TIMESTAMP"`
}

func (RemediationTicket) TableName() string {
	return "remediation_tickets"
}

type RemediationTicketLog struct {
	base.Base

	TicketId  uint64  `gorm:"type:bigint(20) unsigned;not null"`
	Message   *string `gorm:"type:VARCHAR(255)"`
	ToPhase   *string `gorm:"type:VARCHAR(255)"`
	FromPhase *string `gorm:"type:VARCHAR(255)"`
	Action    *string `gorm:"type:VARCHAR(255)"`
}

func (RemediationTicketLog) TableName() string {
	return "remediation_ticket_logs"
}

type RemediationTicketApprovals struct {
	base.Base

	TicketId   uint64   `gorm:"type:bigint(20) unsigned;not null"`
	FromPhase  string   `gorm:"type:VARCHAR(255)"`
	ToPhase    string   `gorm:"type:VARCHAR(255)"`
	ApprovalID *base.ID `gorm:"type:bigint(20) unsigned;not null"`
	Message    string   `gorm:"type:VARCHAR(255)"`
}

func (RemediationTicketApprovals) TableName() string {
	return "remediation_ticket_approvals"
}
