package cliniccli

import (
	"time"

	"github.com/prometheus/common/model"
)

const (
	ClusterTypeOp    string = ""
	ClusterTypeCloud string = "cloud"

	DeployTypeDedicated    string = "dedicated"
	DeployTypeShared       string = "shared"
	DeployTypeByoc         string = "byoc"
	DeployTypePremium      string = "premium"
	DeployTypeTiupCluster  string = "tiup-cluster"
	DeployTypeTiDBOperator string = "tidb-operator"

	ClusterStatusNormal         string = "normal"
	ClusterStatusInitializing   string = "initializing"
	ClusterStatusUpgrading      string = "upgrading"
	ClusterStatusScaling        string = "scaling"
	ClusterStatusCleared        string = "cleared"
	ClusterStatusDeleted        string = "deleted"
	ClusterStatusDeleteComplete string = "deletecomplete"
)

type ClusterFilter struct {
	ClusterStatus []string
	DeployType    []string
	ClusterIds    []string
	ShowDeleted   bool
	CreatedAfter  int64
	CreatedBefore int64
	DeletedAfter  int64
	DeletedBefore int64
}

type Cluster struct {
	OrgID         string `json:"orgID"` // NOTE: org id in clinic
	TenantID      string `json:"tenantID"`
	TenantName    string `json:"tenantName"`
	ClusterID     string `json:"clusterID"`
	ClusterName   string `json:"clusterName"`
	ClusterStatus string `json:"clusterStatus"`
}

type Organization struct {
	ID               string   `json:"id,omitempty"`
	Name             string   `json:"name"`
	Description      string   `json:"description"`
	ClusterCount     int      `json:"clusterCount"`
	LastUpdated      int64    `json:"lastUpdated"`
	RoleNames        []string `json:"roleNames"`
	OrganizationType string   `json:"type"`
	IsStarred        bool     `json:"isStarred"`
	Owner            string   `json:"owner"`
	ExternalID       string   `json:"externalID"`
	EmailDomain      string   `json:"emailDomain"`
}

type QueryMetricData struct {
	ResultType model.ValueType `json:"resultType"`
	Result     model.Matrix    `json:"result"`
}

type QueryMetricResponse struct {
	Status    string          `json:"status"`
	IsPartial bool            `json:"isPartial"`
	Data      QueryMetricData `json:"data"`
}

type ListClustersResponse struct {
	Total int       `json:"total"`
	Items []Cluster `json:"items"`
}

type AddClusterRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	CreatedAt   uint64 `json:"createAt"`
	ClusterType string `json:"clusterType"`
	DeployType  string `json:"deployType"`
	ClusterID   string `json:"clusterID"`
	ProjectID   string `json:"projectID"`
	Region      string `json:"region"`
	Provider    string `json:"provider"`
}

type AddClusterResponse struct {
	ID string `json:"id"`
}

type UpdateClusterStatusReq struct {
	Status string `json:"status"`
}

type QueryClusterMetricsRequest struct {
	OrgID     string    `json:"org_id"`
	ClusterID string    `json:"cluster_id"`
	PromQL    string    `json:"promql"`
	Start     time.Time `json:"start"`
	End       time.Time `json:"end"`
	Step      string    `json:"step"`
}
