package entity

import (
	"github.com/tidbcloud/devops/entity/tenant"
)

type SLA struct {
	MonthlyTrends []SeriesMonthlyTrend `json:"monthlyTrends"`
	Current       float64              `json:"current"`
}

type SLAInfo struct {
	DedicatedSLA  *SLA `json:"dedicatedSLA"`
	ServerlessSLA *SLA `json:"serverlessSLA"`
	NextGenSLA    *SLA `json:"nextGenSLA"`
}

type SLOInfo struct {
	CurrentSummary []ApplicationSLOSummary `json:"currentSummary"`
}

type DedicatedSLAFilter struct {
	Search           string // search by cluster id/name or tenant id/name
	IncludeDeleted   bool
	Status           []SLAStatus
	TiDBInstanceMode TiDBInstanceMode
}

type NextGenSLAFilter struct {
	Search            string // search by cluster id/name or tenant id/name
	IncludeDeleted    bool
	Status            []SLAStatus
	ClusterDeployType string
}

type SLAStatus string

const (
	SLAStatusPerfect SLAStatus = "perfect"
	SLAStatusWarning SLAStatus = "warning"
	SLAStatusBreach  SLAStatus = "breach"
)

type TiDBInstanceMode string

const (
	TiDBInstanceSingle TiDBInstanceMode = "single"
	TiDBInstanceMulti  TiDBInstanceMode = "multi"
)

type DedicatedClusterSLABasicList struct {
	Items []DedicatedClusterSLABasic `json:"items"`
}

type DedicatedClusterSLABasic struct {
	ClusterID    string    `json:"clusterID"`
	ClusterName  string    `json:"clusterName"`
	TenantID     string    `json:"tenantID"`
	TenantName   string    `json:"tenantName"`
	TiDBInstance int       `json:"tidbInstance"`
	Deleted      bool      `json:"deleted"`
	SLAValue     float64   `json:"slaValue"`
	SLAStatus    SLAStatus `json:"slaStatus"`
	IssueKey     string    `json:"issueKey"`
	IssueStatus  string    `json:"issueStatus"`
}

type ClusterDowntime struct {
	Timestamp string `json:"timestamp"`
	Fake      bool   `json:"fake"`
	Comment   string `json:"comment"`
}

type DedicatedClusterSLADetail struct {
	DedicatedClusterSLABasic `json:",inline"`
	DowntimeList             []ClusterDowntime `json:"downtimeList"`
}

type NextGenClusterSLADetail struct {
	NextGenClusterSLABasic `json:",inline"`
	DowntimeList           []ClusterDowntime `json:"downtimeList"`
}

type NextGenClusterSLABasicList struct {
	Items []NextGenClusterSLABasic `json:"items"`
}

type NextGenClusterSLABasic struct {
	ClusterID         string    `json:"clusterID"`
	ClusterName       string    `json:"clusterName"`
	ClusterDeployType string    `json:"clusterDeployType"`
	TenantID          string    `json:"tenantID"`
	TenantName        string    `json:"tenantName"`
	Deleted           bool      `json:"deleted"`
	SLAValue          float64   `json:"slaValue"`
	SLAStatus         SLAStatus `json:"slaStatus"`
	IssueKey          string    `json:"issueKey"`
	IssueStatus       string    `json:"issueStatus"`
}

type ApplicationSLOSummary struct {
	Application string `json:"application"`
	SLOs        []SLO  `json:"slos"`
}

type SLO struct {
	Name   string `json:"name"`
	Met    bool   `json:"met"`
	Reason string `json:"reason"`
}

type IncidentInfo struct {
	Total             int            `json:"total"`
	MTTRInMinutes     float64        `json:"mttrInMinutes"`
	MTTRMonthlyTrends []MonthlyTrend `json:"mttrMonthlyTrends"`
}

type SeriesMonthlyTrend struct {
	Month  string `json:"month"`
	Series string `json:"series"`
	Value  int    `json:"value"`
}

type MonthlyTrend struct {
	Month string  `json:"month"`
	Value float64 `json:"value"`
}

type WeeklyTrend struct {
	Week  string  `json:"week"`
	Value float64 `json:"value"`
}

type CloudOncallInfo struct {
	Total                  int                  `json:"total"`
	BacklogTotal           int                  `json:"backlogTotal"`
	TotalMonthlyTrends     []MonthlyTrend       `json:"monthlyTrend"`
	TTRInDays              float64              `json:"ttrInDays"`
	ComponentMonthlyTrends []SeriesMonthlyTrend `json:"componentMonthlyTrend"`
	PriorityMonthlyTrends  []SeriesMonthlyTrend `json:"priorityMonthlyTrends"`
	TopTenants             []TopTenant          `json:"topTenants"`
}

type CriticalAlertInfo struct {
	Total                  int                  `json:"total"`
	BacklogTotal           int                  `json:"backlogTotal"`
	TTRInDays              float64              `json:"ttrInDays"`
	TopTenants             []TopTenant          `json:"topTenants"`
	AlertMonthlyTrend      []SeriesMonthlyTrend `json:"alertMonthlyTrend"`
	MajorAlertMonthlyTrend []SeriesMonthlyTrend `json:"majorAlertMonthlyTrend"`
}

type ReleaseInfo struct {
	SprintTotal                    int                  `json:"sprintTotal"`
	SprintApplicationMonthlyTrends []SeriesMonthlyTrend `json:"sprintApplicationMonthlyTrends"`
	HotfixTotal                    int                  `json:"hotfixTotal"`
	HotfixApplicationMonthlyTrends []SeriesMonthlyTrend `json:"hotfixApplicationMonthlyTrends"`
}

type TopTenants struct {
	Items []TopTenant `json:"items"`
}

type TopTenant struct {
	ID     uint64              `json:"id,string"`
	Name   string              `json:"name"`
	Alias  string              `json:"alias"`
	Region tenant.TenantRegion `json:"region"`
	Value  int64               `json:"value"`
}

type TopClusters struct {
	Items []TopCluster `json:"items"`
}

type TopCluster struct {
	ID           uint64              `json:"id,string"`
	Name         string              `json:"name"`
	TenantID     uint64              `json:"tenantID,string"`
	TenantName   string              `json:"tenantName"`
	TenantRegion tenant.TenantRegion `json:"tenantRegion"`
	Value        int64               `json:"value"`
}
