package entity

import (
	globaldedicatedv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/dedicated/v1"
)

const (
	DefaultRaftLogDirPath   = "/var/lib/raft/data"
	DefaultRaftLogSpillPath = "/var/lib/tikv/raft-spill"
)

var (
	ComponentsHaveStorage = map[globaldedicatedv1.ComponentType]string{
		globaldedicatedv1.ComponentType_TIKV:    globaldedicatedv1.ComponentType_TIKV.String(),
		globaldedicatedv1.ComponentType_TIFLASH: globaldedicatedv1.ComponentType_TIFLASH.String(),
		globaldedicatedv1.ComponentType_PD:      globaldedicatedv1.ComponentType_PD.String(),
	}

	ComponentsHaveExtraGroup = map[globaldedicatedv1.ComponentType]string{
		globaldedicatedv1.ComponentType_TIDB:    globaldedicatedv1.ComponentType_TIDB.String(),
		globaldedicatedv1.ComponentType_TIPROXY: globaldedicatedv1.ComponentType_TIPROXY.String(),
	}

	ComponentsUserEditable = map[globaldedicatedv1.ComponentType]string{
		globaldedicatedv1.ComponentType_TIDB:    globaldedicatedv1.ComponentType_TIDB.String(),
		globaldedicatedv1.ComponentType_TIKV:    globaldedicatedv1.ComponentType_TIKV.String(),
		globaldedicatedv1.ComponentType_TIFLASH: globaldedicatedv1.ComponentType_TIFLASH.String(),
		globaldedicatedv1.ComponentType_TIPROXY: globaldedicatedv1.ComponentType_TIPROXY.String(),
	}

	// ComponentsCpuHomogeneous is a mapping of cluster components that require consistent CPU generation.
	// The SKUs of these components within a cluster must maintain homogeneous CPU generation.
	// The mapping is used for AWS ARM instance CPU generation homogeneous check: Graviton2 or Graviton4.
	ComponentsCpuHomogeneous = map[globaldedicatedv1.ComponentType]string{
		globaldedicatedv1.ComponentType_TIDB:    globaldedicatedv1.ComponentType_TIDB.String(),
		globaldedicatedv1.ComponentType_PD:      globaldedicatedv1.ComponentType_PD.String(),
		globaldedicatedv1.ComponentType_TIKV:    globaldedicatedv1.ComponentType_TIKV.String(),
		globaldedicatedv1.ComponentType_TIFLASH: globaldedicatedv1.ComponentType_TIFLASH.String(),
	}
)

type (
	Cluster struct {
		*globaldedicatedv1.Cluster

		// A cluster object could have 3 types of components:
		//  - Current components: the components that are already in the cluster. Load from repo.
		//  - Requested components: the components that are requested to be modified. Original body of the grpc request.
		//  - Desired components: the components computed. Based on requested components, current components and SKUs.
		DesiredComponents    []*DesiredClusterComponent
		CurrentComponentSkus map[string]*Sku

		OnNewArch             bool
		ClusterIdentifierHash string
	}

	DesiredClusterComponent struct {
		*ClusterComponent

		Sku *Sku
	}

	ClusterComponent        = globaldedicatedv1.Cluster_ClusterComponent
	State                   = globaldedicatedv1.Cluster_State
	ClusterConfiguration    = globaldedicatedv1.ClusterConfiguration
	ClusterComponentStorage = globaldedicatedv1.Cluster_ClusterComponent_Storage
	ComponentType           = globaldedicatedv1.ComponentType
)
