package main

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

var tikvCount = uint32(3)
var tidbCount = uint32(2)
var tiflashCount = uint32(1)
var pdCount = uint32(3)

var throuput = uint32(400)
var iops = uint32(4000)
var sizeGi = uint32(10)

func volumeType2ptrVolumeType(s dedicatedv1.StorageMu_VolumeType) *dedicatedv1.StorageMu_VolumeType {
	return &s
}
func buildClusters() []*tidb_mgmt_servicev1.Cluster {
	return []*tidb_mgmt_servicev1.Cluster{
		buildCluster("test-creating", uint64(10001), uint64(10002), uint64(10003), dedicatedv1.Cluster_CREATING),
		buildCluster("test-available", uint64(20001), uint64(20002), uint64(20003), dedicatedv1.Cluster_AVAILABLE),
		buildCluster("test-paused", uint64(40001), uint64(40002), uint64(40003), dedicatedv1.Cluster_PAUSED),
		buildCluster("test-resuming", uint64(50001), uint64(50002), uint64(50003), dedicatedv1.Cluster_RESUMING),
		buildCluster("test-unavailable", uint64(60001), uint64(60002), uint64(60003), dedicatedv1.Cluster_UNAVAILABLE),
		buildCluster("test-pausing", uint64(70001), uint64(70002), uint64(70003), dedicatedv1.Cluster_PAUSING),
		buildCluster("test-scaling", uint64(80001), uint64(80002), uint64(80003), dedicatedv1.Cluster_SCALING),
		buildCluster("test-deleted", uint64(90001), uint64(90002), uint64(90003), dedicatedv1.Cluster_DELETED),
	}
}

func buildCluster(clusterName string, clusterID, projectID, orgID uint64, state dedicatedv1.Cluster_State) *tidb_mgmt_servicev1.Cluster {
	cluster := &tidb_mgmt_servicev1.Cluster{
		OrganizationId: orgID,
		ClusterId:      clusterID,
		ProjectId:      projectID,
		ClusterName:    clusterName,
		CloudProvider:  "aws",
		DeployType:     1,
		Region:         "us-west-2",
		ClusterInfo: &tidb_mgmt_servicev1.Cluster_DedicatedCluster{
			DedicatedCluster: &dedicatedv1.Cluster{
				OrganizationId: orgID,
				ClusterId:      clusterID,
				ProjectId:      projectID,
				State:          state,
				ClusterComponents: []*dedicatedv1.Cluster_ClusterComponent{
					{
						ComponentType: dedicatedv1.ComponentType_TIKV,
						Count:         &tikvCount,
						CpuNum:        uint32(2),
						MemorySizeGi:  uint32(4),
						InstanceType:  "t4g.medium",
						MeteringSkuKeys: map[string]uint32{
							"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
						},
						Storages: map[string]*dedicatedv1.Cluster_ClusterComponent_Storage{
							"data": {
								VolumeType:      volumeType2ptrVolumeType(dedicatedv1.StorageMu_GP3),
								SizeGi:          sizeGi,
								Iops:            iops,
								ThroughputMibps: throuput,
								MeteringSkuKeys: map[string]uint32{
									"disk-iops:aws:us-west-2:gp3":       iops,
									"disk-throughput:aws:us-west-2:gp3": throuput,
									"disk-storage:aws:us-west-2:gp3":    sizeGi,
								},
							},
						},
					},
					{
						ComponentType: dedicatedv1.ComponentType_PD,
						Count:         &pdCount,
						CpuNum:        uint32(2),
						MemorySizeGi:  uint32(4),
						InstanceType:  "t4g.medium",
						MeteringSkuKeys: map[string]uint32{
							"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
						},
						Storages: map[string]*dedicatedv1.Cluster_ClusterComponent_Storage{
							"data": {
								VolumeType:      volumeType2ptrVolumeType(dedicatedv1.StorageMu_GP3),
								SizeGi:          sizeGi,
								Iops:            iops,
								ThroughputMibps: throuput,
								MeteringSkuKeys: map[string]uint32{
									"disk-iops:aws:us-west-2:gp3":       iops,
									"disk-throughput:aws:us-west-2:gp3": throuput,
									"disk-storage:aws:us-west-2:gp3":    sizeGi,
								},
							},
						},
					},
					{
						ComponentType:        dedicatedv1.ComponentType_TIDB,
						Count:                &tidbCount,
						CpuNum:               uint32(2),
						MemorySizeGi:         uint32(4),
						InstanceType:         "t4g.medium",
						TidbGroupDisplayName: "1795007861923794944",
						MeteringSkuKeys: map[string]uint32{
							"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
						},
					},
					{
						ComponentType: dedicatedv1.ComponentType_TIFLASH,
						Count:         &tiflashCount,
						CpuNum:        uint32(2),
						MemorySizeGi:  uint32(4),
						InstanceType:  "t4g.medium",
						MeteringSkuKeys: map[string]uint32{
							"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
						},
						Storages: map[string]*dedicatedv1.Cluster_ClusterComponent_Storage{
							"data": {
								VolumeType:      volumeType2ptrVolumeType(dedicatedv1.StorageMu_GP3),
								SizeGi:          sizeGi,
								Iops:            iops,
								ThroughputMibps: throuput,
								MeteringSkuKeys: map[string]uint32{
									"disk-iops:aws:us-west-2:gp3":       iops,
									"disk-throughput:aws:us-west-2:gp3": throuput,
									"disk-storage:aws:us-west-2:gp3":    sizeGi,
								},
							},
						},
					},
				},
			},
		},
	}
	return cluster
}

func buildScalingComponentInfo() *dedicatedv1.ComponentNodeInfo {
	componentInfo := &dedicatedv1.ComponentNodeInfo{
		Tidb: []*dedicatedv1.ComponentNodeInfo_Component{
			{
				Nodes: []*dedicatedv1.ComponentNodeInfo_Component_Node{
					{
						State:                  dedicatedv1.ComponentNodeInfo_Component_Node_AVAILABLE,
						Cpu:                    uint32(2),
						MemorySizeGi:           uint32(4),
						StorageSizeGi:          sizeGi,
						StorageIops:            iops,
						StorageThroughputMibps: throuput,
						InstanceType:           "t4g.medium",
						VolumeType:             dedicatedv1.StorageMu_GP3,
						MeteringSkuKeys: map[string]uint32{
							"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
						},
						Storages: map[string]*dedicatedv1.ComponentNodeInfo_Component_Storage{
							"data": {
								VolumeType:             dedicatedv1.StorageMu_GP3,
								StorageSizeGi:          sizeGi,
								StorageIops:            iops,
								StorageThroughputMibps: throuput,
								MeteringSkuKeys: map[string]uint32{
									"disk-iops:aws:us-west-2:gp3":       iops,
									"disk-throughput:aws:us-west-2:gp3": throuput,
									"disk-storage:aws:us-west-2:gp3":    sizeGi,
								},
							},
						},
					},
					{
						State:                  dedicatedv1.ComponentNodeInfo_Component_Node_DELETING,
						Cpu:                    uint32(2),
						MemorySizeGi:           uint32(4),
						StorageSizeGi:          sizeGi,
						StorageIops:            iops,
						StorageThroughputMibps: throuput,
						InstanceType:           "t4g.medium",
						VolumeType:             dedicatedv1.StorageMu_GP3,
						MeteringSkuKeys: map[string]uint32{
							"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
						},
						Storages: map[string]*dedicatedv1.ComponentNodeInfo_Component_Storage{
							"data": {
								VolumeType:             dedicatedv1.StorageMu_GP3,
								StorageSizeGi:          sizeGi,
								StorageIops:            iops,
								StorageThroughputMibps: throuput,
								MeteringSkuKeys: map[string]uint32{
									"disk-iops:aws:us-west-2:gp3":       iops,
									"disk-throughput:aws:us-west-2:gp3": throuput,
									"disk-storage:aws:us-west-2:gp3":    sizeGi,
								},
							},
						},
					},
					{
						State:                  dedicatedv1.ComponentNodeInfo_Component_Node_UNAVAILABLE,
						Cpu:                    uint32(2),
						MemorySizeGi:           uint32(4),
						StorageSizeGi:          sizeGi,
						StorageIops:            iops,
						StorageThroughputMibps: throuput,
						InstanceType:           "t4g.medium",
						VolumeType:             dedicatedv1.StorageMu_GP3,
						MeteringSkuKeys: map[string]uint32{
							"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
						},
						Storages: map[string]*dedicatedv1.ComponentNodeInfo_Component_Storage{
							"data": {
								VolumeType:             dedicatedv1.StorageMu_GP3,
								StorageSizeGi:          sizeGi,
								StorageIops:            iops,
								StorageThroughputMibps: throuput,
								MeteringSkuKeys: map[string]uint32{
									"disk-iops:aws:us-west-2:gp3":       iops,
									"disk-throughput:aws:us-west-2:gp3": throuput,
									"disk-storage:aws:us-west-2:gp3":    sizeGi,
								},
							},
						},
					},
					{
						State:                  dedicatedv1.ComponentNodeInfo_Component_Node_CREATING,
						Cpu:                    uint32(2),
						MemorySizeGi:           uint32(4),
						StorageSizeGi:          sizeGi,
						StorageIops:            iops,
						StorageThroughputMibps: throuput,
						InstanceType:           "t4g.medium",
						VolumeType:             dedicatedv1.StorageMu_GP3,
						MeteringSkuKeys: map[string]uint32{
							"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
						},
						Storages: map[string]*dedicatedv1.ComponentNodeInfo_Component_Storage{
							"data": {
								VolumeType:             dedicatedv1.StorageMu_GP3,
								StorageSizeGi:          sizeGi,
								StorageIops:            iops,
								StorageThroughputMibps: throuput,
								MeteringSkuKeys: map[string]uint32{
									"disk-iops:aws:us-west-2:gp3":       iops,
									"disk-throughput:aws:us-west-2:gp3": throuput,
									"disk-storage:aws:us-west-2:gp3":    sizeGi,
								},
							},
						},
					},
				},
				TidbGroupId:          uint64(1213344),
				TidbGroupDisplayName: "aaa",
				IsDefaultTidbGroup:   true,
			},
			{
				Nodes: []*dedicatedv1.ComponentNodeInfo_Component_Node{
					{
						State:                  dedicatedv1.ComponentNodeInfo_Component_Node_AVAILABLE,
						Cpu:                    uint32(4),
						MemorySizeGi:           uint32(8),
						StorageSizeGi:          sizeGi,
						StorageIops:            iops,
						StorageThroughputMibps: throuput,
						InstanceType:           "t4g.large",
						VolumeType:             dedicatedv1.StorageMu_GP3,
						MeteringSkuKeys: map[string]uint32{
							"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.large": 1,
						},
					},
				},
				TidbGroupId:          uint64(23432342),
				TidbGroupDisplayName: "bbb",
				IsDefaultTidbGroup:   false,
			},
		},
		Tikv: &dedicatedv1.ComponentNodeInfo_Component{
			Nodes: []*dedicatedv1.ComponentNodeInfo_Component_Node{
				{
					State:                  dedicatedv1.ComponentNodeInfo_Component_Node_AVAILABLE,
					Cpu:                    uint32(2),
					MemorySizeGi:           uint32(4),
					StorageSizeGi:          sizeGi,
					StorageIops:            iops,
					StorageThroughputMibps: throuput,
					InstanceType:           "t4g.medium",
					VolumeType:             dedicatedv1.StorageMu_GP3,
					MeteringSkuKeys: map[string]uint32{
						"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
					},
					Storages: map[string]*dedicatedv1.ComponentNodeInfo_Component_Storage{
						"data": {
							VolumeType:             dedicatedv1.StorageMu_GP3,
							StorageSizeGi:          sizeGi,
							StorageIops:            iops,
							StorageThroughputMibps: throuput,
							MeteringSkuKeys: map[string]uint32{
								"disk-iops:aws:us-west-2:gp3":       iops,
								"disk-throughput:aws:us-west-2:gp3": throuput,
								"disk-storage:aws:us-west-2:gp3":    sizeGi,
							},
						},
					},
				},
				{
					State:                  dedicatedv1.ComponentNodeInfo_Component_Node_DELETING,
					Cpu:                    uint32(2),
					MemorySizeGi:           uint32(4),
					StorageSizeGi:          sizeGi,
					StorageIops:            iops,
					StorageThroughputMibps: throuput,
					InstanceType:           "t4g.medium",
					VolumeType:             dedicatedv1.StorageMu_GP3,
					MeteringSkuKeys: map[string]uint32{
						"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
					},
					Storages: map[string]*dedicatedv1.ComponentNodeInfo_Component_Storage{
						"data": {
							VolumeType:             dedicatedv1.StorageMu_GP3,
							StorageSizeGi:          sizeGi,
							StorageIops:            iops,
							StorageThroughputMibps: throuput,
							MeteringSkuKeys: map[string]uint32{
								"disk-iops:aws:us-west-2:gp3":       iops,
								"disk-throughput:aws:us-west-2:gp3": throuput,
								"disk-storage:aws:us-west-2:gp3":    sizeGi,
							},
						},
					},
				},
				{
					State:                  dedicatedv1.ComponentNodeInfo_Component_Node_UNAVAILABLE,
					Cpu:                    uint32(2),
					MemorySizeGi:           uint32(4),
					StorageSizeGi:          sizeGi,
					StorageIops:            iops,
					StorageThroughputMibps: throuput,
					InstanceType:           "t4g.medium",
					VolumeType:             dedicatedv1.StorageMu_GP3,
					MeteringSkuKeys: map[string]uint32{
						"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
					},
					Storages: map[string]*dedicatedv1.ComponentNodeInfo_Component_Storage{
						"data": {
							VolumeType:             dedicatedv1.StorageMu_GP3,
							StorageSizeGi:          sizeGi,
							StorageIops:            iops,
							StorageThroughputMibps: throuput,
							MeteringSkuKeys: map[string]uint32{
								"disk-iops:aws:us-west-2:gp3":       iops,
								"disk-throughput:aws:us-west-2:gp3": throuput,
								"disk-storage:aws:us-west-2:gp3":    sizeGi,
							},
						},
					},
				},
				{
					State:                  dedicatedv1.ComponentNodeInfo_Component_Node_CREATING,
					Cpu:                    uint32(2),
					MemorySizeGi:           uint32(4),
					StorageSizeGi:          sizeGi,
					StorageIops:            iops,
					StorageThroughputMibps: throuput,
					InstanceType:           "t4g.medium",
					VolumeType:             dedicatedv1.StorageMu_GP3,
					MeteringSkuKeys: map[string]uint32{
						"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
					},
					Storages: map[string]*dedicatedv1.ComponentNodeInfo_Component_Storage{
						"data": {
							VolumeType:             dedicatedv1.StorageMu_GP3,
							StorageSizeGi:          sizeGi,
							StorageIops:            iops,
							StorageThroughputMibps: throuput,
							MeteringSkuKeys: map[string]uint32{
								"disk-iops:aws:us-west-2:gp3":       iops,
								"disk-throughput:aws:us-west-2:gp3": throuput,
								"disk-storage:aws:us-west-2:gp3":    sizeGi,
							},
						},
					},
				},
			},
		},
		Tiflash: &dedicatedv1.ComponentNodeInfo_Component{
			Nodes: []*dedicatedv1.ComponentNodeInfo_Component_Node{
				{
					State:                  dedicatedv1.ComponentNodeInfo_Component_Node_AVAILABLE,
					Cpu:                    uint32(2),
					MemorySizeGi:           uint32(4),
					StorageSizeGi:          sizeGi,
					StorageIops:            iops,
					StorageThroughputMibps: throuput,
					InstanceType:           "t4g.medium",
					VolumeType:             dedicatedv1.StorageMu_GP3,
					MeteringSkuKeys: map[string]uint32{
						"node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium": 1,
					},
					Storages: map[string]*dedicatedv1.ComponentNodeInfo_Component_Storage{
						"data": {
							VolumeType:             dedicatedv1.StorageMu_GP3,
							StorageSizeGi:          sizeGi,
							StorageIops:            iops,
							StorageThroughputMibps: throuput,
							MeteringSkuKeys: map[string]uint32{
								"disk-iops:aws:us-west-2:gp3":       iops,
								"disk-throughput:aws:us-west-2:gp3": throuput,
								"disk-storage:aws:us-west-2:gp3":    sizeGi,
							},
						},
					},
				},
			},
		},
	}

	return componentInfo
}
