package cluster

import (
	"context"

	pkgv2db "github.com/tidbcloud/pkgv2/db"
	"github.com/tidbcloud/tiinf/monitor/tilog"
	"go.uber.org/zap"
	"gorm.io/gorm"

	globalcommonv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/common/v1"
	globaldedicatedv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/dedicated/v1"
	"github.com/tidbcloud/tidb-management-service/dedicated-global-service/domain/entity"
	spusvc "github.com/tidbcloud/tidb-management-service/dedicated-global-service/domain/service/spu"
	clusterrepoimpl "github.com/tidbcloud/tidb-management-service/dedicated-global-service/infra/repoimpl/cluster"
	regionimpl "github.com/tidbcloud/tidb-management-service/dedicated-global-service/infra/repoimpl/region"
	"github.com/tidbcloud/tidb-management-service/dedicated-global-service/infra/repoimpl/schema"
	spurepoimpl "github.com/tidbcloud/tidb-management-service/dedicated-global-service/infra/repoimpl/spu"
	"github.com/tidbcloud/tidb-management-service/dedicated-global-service/pkg/tempomigrate/convert"
)

const (
	TenantID       = 1
	ProjectID      = 300008
	CidrID         = 123
	ClusterVersion = "v8.5.2"
)

func initDBRegionRecord(ctx context.Context, d pkgv2db.Provider) error {
	providers := convert.GetDedicateGlobalProviders()
	for i := range providers {
		if err := d.WriteDB(ctx).Create(providers[i]).Error; err != nil {
			return err
		}
	}

	regions := convert.GetDedicateGlobalRegions()
	for i := range regions {
		regions[i].Status = "active"
		if err := d.WriteDB(ctx).Create(regions[i]).Error; err != nil {
			return err
		}
	}

	return nil
}

func initDBSkuRecords(ctx context.Context) error {
	spuRepo := spurepoimpl.NewSpuRepo(*dbProvider.Load())
	skuRepo := spurepoimpl.NewSkuRepo(*dbProvider.Load())
	instanceMuRepo := spurepoimpl.NewInstanceMuRepo(*dbProvider.Load())
	storageMuRepo := spurepoimpl.NewStorageMuRepo(*dbProvider.Load())
	regionRepo := regionimpl.NewRegionRepo(*dbProvider.Load())
	clusterRepo := clusterrepoimpl.NewClusterRepo(*dbProvider.Load())
	skuSvc := spusvc.NewSkuService(spuRepo, skuRepo, instanceMuRepo, storageMuRepo)
	spuSvc := spusvc.NewSpuService(spuRepo, skuRepo, regionRepo, clusterRepo, skuSvc, nil, *dbProvider.Load())

	// instance MUs.
	instance8C8GArmId, err := instanceMuRepo.Save(ctx, &entity.InstanceMu{
		CloudProvider: globalcommonv1.CloudProvider_AWS,
		InstanceType:  "instance_type_8c8g_arm_6g.",
		CpuCore:       8,
		MemoryGi:      8,
		CpuArch:       globaldedicatedv1.InstanceMu_ARM64,
	})
	if err != nil {
		return err
	}
	instance7C7GArmId, err := instanceMuRepo.Save(ctx, &entity.InstanceMu{
		CloudProvider: globalcommonv1.CloudProvider_AWS,
		InstanceType:  "instance_type_7c7g_arm_6g.",
		CpuCore:       7,
		MemoryGi:      7,
		CpuArch:       globaldedicatedv1.InstanceMu_ARM64,
	})
	if err != nil {
		return err
	}
	instance2C2GArmId, err := instanceMuRepo.Save(ctx, &entity.InstanceMu{
		CloudProvider: globalcommonv1.CloudProvider_AWS,
		InstanceType:  "instance_type_2c2g_arm_6g.",
		CpuCore:       2,
		MemoryGi:      2,
		CpuArch:       globaldedicatedv1.InstanceMu_ARM64,
	})
	if err != nil {
		return err
	}
	instance8C8GGcpId, err := instanceMuRepo.Save(ctx, &entity.InstanceMu{
		CloudProvider: globalcommonv1.CloudProvider_GCP,
		InstanceType:  "instance_type_8c8g_gcp",
		CpuCore:       8,
		MemoryGi:      8,
		CpuArch:       globaldedicatedv1.InstanceMu_AMD64,
	})
	if err != nil {
		return err
	}
	instance8C8GX86Id, err := instanceMuRepo.Save(ctx, &entity.InstanceMu{
		CloudProvider: globalcommonv1.CloudProvider_AWS,
		InstanceType:  "instance_type_8c8g_x86",
		CpuCore:       8,
		MemoryGi:      8,
		CpuArch:       globaldedicatedv1.InstanceMu_AMD64,
	})
	if err != nil {
		return err
	}
	instance9C9GArmId, err := instanceMuRepo.Save(ctx, &entity.InstanceMu{
		CloudProvider: globalcommonv1.CloudProvider_AWS,
		InstanceType:  "instance_type_9c9g_arm_6g.",
		CpuCore:       9,
		MemoryGi:      9,
		CpuArch:       globaldedicatedv1.InstanceMu_ARM64,
	})
	if err != nil {
		return err
	}
	instance16C16GArmId, err := instanceMuRepo.Save(ctx, &entity.InstanceMu{
		CloudProvider: globalcommonv1.CloudProvider_AWS,
		InstanceType:  "instance_type_16c16g_arm_6g.",
		CpuCore:       16,
		MemoryGi:      16,
		CpuArch:       globaldedicatedv1.InstanceMu_ARM64,
	})
	if err != nil {
		return err
	}

	// storage MUs.
	gp3Id, err := storageMuRepo.Save(ctx, &entity.StorageMu{
		CloudProvider: globalcommonv1.CloudProvider_AWS,
		VolumeType:    globaldedicatedv1.StorageMu_GP3,
	})
	if err != nil {
		return err
	}
	io2Id, err := storageMuRepo.Save(ctx, &entity.StorageMu{
		CloudProvider: globalcommonv1.CloudProvider_AWS,
		VolumeType:    globaldedicatedv1.StorageMu_IO2,
	})
	if err != nil {
		return err
	}
	pdssdId, err := storageMuRepo.Save(ctx, &entity.StorageMu{
		CloudProvider: globalcommonv1.CloudProvider_GCP,
		VolumeType:    globaldedicatedv1.StorageMu_PD_SSD,
	})
	if err != nil {
		return err
	}

	// tikv spu.
	spuTikv16C16G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "16c16g",
		Name:          "16c16g",
		ComponentType: globaldedicatedv1.ComponentType_TIKV,
		CpuCore:       16,
		MemorySizeGi:  16,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-16c16g-arm-data:gp3-raft:none-fixed",
			},
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-16c16g-arm-data:gp3-raft:gp3-dynamic",
			},
		},
	})
	if err != nil {
		return err
	}
	spuTikv8C8G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "8c8g",
		Name:          "8c8g",
		ComponentType: globaldedicatedv1.ComponentType_TIKV,
		CpuCore:       8,
		MemorySizeGi:  8,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-8c8g-x86-data:gp3-raft:none-fixed",
			},
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-8c8g-arm-data:gp3-raft:io2-dynamic",
			},
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-8c8g-arm-data:gp3-raft:gp3-dynamic",
			},
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-8c8g-arm-data:gp3-raft:none-fixed",
			},
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-8c8g-arm-data:io2-raft:none-fixed",
			},
			{
				CloudProvider:   globalcommonv1.CloudProvider_GCP,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_GCP_US_WEST1},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-8c8g-gcp-data:pd-ssd-raft:none-fixed",
			},
		},
	})
	if err != nil {
		return err
	}
	spuTikv8C8GPlus, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "8c8g-plus",
		Name:          "8c8g-plus",
		ComponentType: globaldedicatedv1.ComponentType_TIKV,
		CpuCore:       8,
		MemorySizeGi:  8,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-8c8g-arm-data:io2-raft:none-fixed:plus",
			},
		},
	})
	if err != nil {
		return err
	}
	spuTikv7C7G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "7c7g",
		Name:          "7c7g",
		ComponentType: globaldedicatedv1.ComponentType_TIKV,
		CpuCore:       7,
		MemorySizeGi:  7,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-7c7g-arm-data:gp3-raft:none-fixed",
			},
		},
	})
	if err != nil {
		return err
	}
	spuTikv2C2G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "2c2g",
		Name:          "2c2g",
		ComponentType: globaldedicatedv1.ComponentType_TIKV,
		CpuCore:       2,
		MemorySizeGi:  2,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tikv-2c2g-arm-data:gp3-raft:none-fixed",
			},
		},
	})
	if err != nil {
		return err
	}

	// tikv skus.
	// 16c16g
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-16c16g-arm-data:gp3-raft:none-fixed",
		SpuId:            spuTikv16C16G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance16C16GArmId),
		DefaultNodeCount: 3,
		Priority:         999,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       99999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-16c16g-arm-data:gp3-raft:gp3-dynamic",
		SpuId:            spuTikv16C16G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance16C16GArmId),
		DefaultNodeCount: 3,
		Priority:         999,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       99999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
		RaftlogStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
	})
	if err != nil {
		return err
	}
	// 8c8g
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-8c8g-arm-data:gp3-raft:io2-dynamic",
		SpuId:            spuTikv8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance8C8GArmId),
		DefaultNodeCount: 3,
		Priority:         999,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       99999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
		RaftlogStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(io2Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       99999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 20,
				},
			},
			ThroughputMibpsMax: 0,
			ThroughputMibpsMin: 0,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputFixed_{
				ThroughputFixed: &globaldedicatedv1.Sku_Storage_ThroughputFixed{
					ThroughputMibps: 0,
				},
			},
		},
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-8c8g-arm-data:gp3-raft:gp3-dynamic",
		SpuId:            spuTikv8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance8C8GArmId),
		DefaultNodeCount: 3,
		Priority:         999,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
		RaftlogStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-8c8g-arm-data:gp3-raft:none-fixed",
		SpuId:            spuTikv8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance8C8GArmId),
		DefaultNodeCount: 3,
		Priority:         999,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsFixed_{
				IopsFixed: &globaldedicatedv1.Sku_Storage_IopsFixed{
					Iops: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputFixed_{
				ThroughputFixed: &globaldedicatedv1.Sku_Storage_ThroughputFixed{
					ThroughputMibps: 1,
				},
			},
		},
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-8c8g-arm-data:io2-raft:none-fixed",
		SpuId:            spuTikv8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance8C8GArmId),
		DefaultNodeCount: 3,
		Priority:         999,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(io2Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsFixed_{
				IopsFixed: &globaldedicatedv1.Sku_Storage_IopsFixed{
					Iops: 1,
				},
			},
			ThroughputMibpsMax: 0,
			ThroughputMibpsMin: 0,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputFixed_{
				ThroughputFixed: &globaldedicatedv1.Sku_Storage_ThroughputFixed{
					ThroughputMibps: 0,
				},
			},
		},
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-8c8g-arm-data:io2-raft:none-fixed:plus",
		SpuId:            spuTikv8C8GPlus.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance8C8GArmId),
		DefaultNodeCount: 3,
		Priority:         0,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(io2Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsFixed_{
				IopsFixed: &globaldedicatedv1.Sku_Storage_IopsFixed{
					Iops: 1,
				},
			},
			ThroughputMibpsMax: 0,
			ThroughputMibpsMin: 0,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputFixed_{
				ThroughputFixed: &globaldedicatedv1.Sku_Storage_ThroughputFixed{
					ThroughputMibps: 0,
				},
			},
		},
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-8c8g-gcp-data:pd-ssd-raft:none-fixed",
		SpuId:            spuTikv8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_GCP,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance8C8GGcpId),
		DefaultNodeCount: 3,
		Priority:         999,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(pdssdId),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
		},
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-8c8g-x86-data:gp3-raft:none-fixed",
		SpuId:            spuTikv8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance8C8GX86Id),
		DefaultNodeCount: 3,
		Priority:         0, // Highest priority.
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			Iops: &globaldedicatedv1.Sku_Storage_IopsFixed_{
				IopsFixed: &globaldedicatedv1.Sku_Storage_IopsFixed{
					Iops: 2,
				},
			},
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputFixed_{
				ThroughputFixed: &globaldedicatedv1.Sku_Storage_ThroughputFixed{
					ThroughputMibps: 1,
				},
			},
		},
	})
	if err != nil {
		return err
	}
	// 7c7g
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-7c7g-arm-data:gp3-raft:none-fixed",
		SpuId:            spuTikv7C7G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance7C7GArmId),
		DefaultNodeCount: 3,
		Priority:         999,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       0,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsFixed_{
				IopsFixed: &globaldedicatedv1.Sku_Storage_IopsFixed{
					Iops: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputFixed_{
				ThroughputFixed: &globaldedicatedv1.Sku_Storage_ThroughputFixed{
					ThroughputMibps: 1,
				},
			},
		},
	})
	if err != nil {
		return err
	}
	// 2c2g
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tikv-2c2g-arm-data:gp3-raft:none-fixed",
		SpuId:            spuTikv2C2G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIKV,
		InstanceMuId:     uint64(instance2C2GArmId),
		DefaultNodeCount: 3,
		Priority:         999,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsFixed_{
				IopsFixed: &globaldedicatedv1.Sku_Storage_IopsFixed{
					Iops: 1,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputFixed_{
				ThroughputFixed: &globaldedicatedv1.Sku_Storage_ThroughputFixed{
					ThroughputMibps: 1,
				},
			},
		},
	})
	if err != nil {
		return err
	}

	// tidb spu.
	spuTidb8C8G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "8c8g",
		Name:          "8c8g",
		ComponentType: globaldedicatedv1.ComponentType_TIDB,
		CpuCore:       8,
		MemorySizeGi:  8,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tidb-8c8g-arm",
			},
			{
				CloudProvider:   globalcommonv1.CloudProvider_GCP,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_GCP_US_WEST1},
				OrganizationIds: []uint64{0},
				SkuKey:          "tidb-8c8g-gcp",
			},
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tidb-8c8g-x86",
			},
		},
	})
	if err != nil {
		return err
	}
	spuTidb7C7G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "7c7g",
		Name:          "7c7g",
		ComponentType: globaldedicatedv1.ComponentType_TIDB,
		CpuCore:       7,
		MemorySizeGi:  7,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tidb-7c7g-arm",
			},
		},
	})
	if err != nil {
		return err
	}
	spuTidb2C2G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "2c2g",
		Name:          "2c2g",
		ComponentType: globaldedicatedv1.ComponentType_TIDB,
		CpuCore:       2,
		MemorySizeGi:  2,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tidb-2c2g-arm",
			},
		},
	})
	if err != nil {
		return err
	}

	// tidb sku.
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tidb-8c8g-arm",
		SpuId:            spuTidb8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIDB,
		InstanceMuId:     uint64(instance8C8GArmId),
		DefaultNodeCount: 2,
		Priority:         0,
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tidb-8c8g-gcp",
		SpuId:            spuTidb8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_GCP,
		ComponentType:    globaldedicatedv1.ComponentType_TIDB,
		InstanceMuId:     uint64(instance8C8GGcpId),
		DefaultNodeCount: 2,
		Priority:         0,
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tidb-8c8g-x86",
		SpuId:            spuTidb8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIDB,
		InstanceMuId:     uint64(instance8C8GX86Id),
		DefaultNodeCount: 2,
		Priority:         0,
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tidb-7c7g-arm",
		SpuId:            spuTidb7C7G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIDB,
		InstanceMuId:     uint64(instance7C7GArmId),
		DefaultNodeCount: 2,
		Priority:         0,
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tidb-2c2g-arm",
		SpuId:            spuTidb2C2G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIDB,
		InstanceMuId:     uint64(instance2C2GArmId),
		DefaultNodeCount: 2,
		Priority:         0,
	})
	if err != nil {
		return err
	}

	// tiflash spu.
	spuTiflash8C8G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "8c8g",
		Name:          "8c8g",
		ComponentType: globaldedicatedv1.ComponentType_TIFLASH,
		CpuCore:       8,
		MemorySizeGi:  8,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tiflash-8c8g-arm-data:gp3-dynamic",
			},
		},
	})
	if err != nil {
		return err
	}
	spuTiflash7C7G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "7c7g",
		Name:          "7c7g",
		ComponentType: globaldedicatedv1.ComponentType_TIFLASH,
		CpuCore:       7,
		MemorySizeGi:  7,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tiflash-7c7g-arm-data:gp3-dynamic",
			},
		},
	})
	if err != nil {
		return err
	}

	// tiflash sku.
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tiflash-8c8g-arm-data:gp3-dynamic",
		SpuId:            spuTiflash8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIFLASH,
		InstanceMuId:     uint64(instance8C8GArmId),
		DefaultNodeCount: 0,
		Priority:         0,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tiflash-7c7g-arm-data:gp3-dynamic",
		SpuId:            spuTiflash7C7G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIFLASH,
		InstanceMuId:     uint64(instance7C7GArmId),
		DefaultNodeCount: 0,
		Priority:         0,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
	})
	if err != nil {
		return err
	}

	// pd spu.
	spuPd16C16G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "16c16g",
		Name:          "16c16g",
		ComponentType: globaldedicatedv1.ComponentType_PD,
		CpuCore:       16,
		MemorySizeGi:  16,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "pd-16c16g-arm-data:gp3-dynamic",
			},
		},
	})
	if err != nil {
		return err
	}
	spuPd9C9G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "9c9g",
		Name:          "9c9g",
		ComponentType: globaldedicatedv1.ComponentType_PD,
		CpuCore:       9,
		MemorySizeGi:  9,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "pd-9c9g-arm-data:gp3-dynamic",
			},
		},
	})
	if err != nil {
		return err
	}
	spuPd8C8G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "8c8g",
		Name:          "8c8g",
		ComponentType: globaldedicatedv1.ComponentType_PD,
		CpuCore:       8,
		MemorySizeGi:  8,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "pd-8c8g-arm-data:gp3-dynamic",
			},
			{
				CloudProvider:   globalcommonv1.CloudProvider_GCP,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_GCP_US_WEST1},
				OrganizationIds: []uint64{0},
				SkuKey:          "pd-8c8g-gcp-data:pd-ssd-fixed",
			},
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "pd-8c8g-x86-data:gp3-dynamic",
			},
		},
	})
	if err != nil {
		return err
	}
	spuPd7C7G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "7c7g",
		Name:          "7c7g",
		ComponentType: globaldedicatedv1.ComponentType_PD,
		CpuCore:       7,
		MemorySizeGi:  7,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "pd-7c7g-arm-data:gp3-dynamic",
			},
		},
	})
	if err != nil {
		return err
	}

	// pd sku.
	// 16c16g
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "pd-16c16g-arm-data:gp3-dynamic",
		SpuId:            spuPd16C16G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_PD,
		InstanceMuId:     uint64(instance16C16GArmId),
		DefaultNodeCount: 3,
		Priority:         0,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
		Conditions: []*globaldedicatedv1.Sku_Condition{
			{
				Key:      globaldedicatedv1.Sku_Condition_ATTACH_TIERUNIT,
				Operator: globaldedicatedv1.Sku_Condition_IN,
				Values: []string{
					"tikv-16c16g-arm-data:gp3-raft:none-fixed",
				},
			},
		},
	})
	if err != nil {
		return err
	}
	// 9c9g
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "pd-9c9g-arm-data:gp3-dynamic",
		SpuId:            spuPd9C9G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_PD,
		InstanceMuId:     uint64(instance9C9GArmId),
		DefaultNodeCount: 3,
		Priority:         0,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
		Conditions: []*globaldedicatedv1.Sku_Condition{},
	})
	if err != nil {
		return err
	}
	// 8c8g
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "pd-8c8g-arm-data:gp3-dynamic",
		SpuId:            spuPd8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_PD,
		InstanceMuId:     uint64(instance8C8GArmId),
		DefaultNodeCount: 3,
		Priority:         0,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
		Conditions: []*globaldedicatedv1.Sku_Condition{
			{
				Key:      globaldedicatedv1.Sku_Condition_ATTACH_TIERUNIT,
				Operator: globaldedicatedv1.Sku_Condition_IN,
				Values: []string{
					"tikv-8c8g-arm-data:gp3-raft:io2-dynamic",
					"tikv-8c8g-arm-data:gp3-raft:gp3-dynamic",
					"tikv-8c8g-arm-data:gp3-raft:none-fixed",
					"tikv-8c8g-arm-data:io2-raft:none-fixed",
					"tikv-7c7g-arm-data:gp3-raft:none-fixed",
					"tikv-8c8g-arm-data:io2-raft:none-fixed:plus",
					"tikv-16c16g-arm-data:gp3-raft:gp3-dynamic",
				},
			},
		},
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "pd-8c8g-gcp-data:pd-ssd-fixed",
		SpuId:            spuPd8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_GCP,
		ComponentType:    globaldedicatedv1.ComponentType_PD,
		InstanceMuId:     uint64(instance8C8GGcpId),
		DefaultNodeCount: 3,
		Priority:         0,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(pdssdId),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
		},
		Conditions: []*globaldedicatedv1.Sku_Condition{
			{
				Key:      globaldedicatedv1.Sku_Condition_ATTACH_TIERUNIT,
				Operator: globaldedicatedv1.Sku_Condition_IN,
				Values: []string{
					"tikv-8c8g-gcp-data:pd-ssd-raft:none-fixed",
				},
			},
		},
	})
	if err != nil {
		return err
	}
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "pd-8c8g-x86-data:gp3-dynamic",
		SpuId:            spuPd8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_PD,
		InstanceMuId:     uint64(instance8C8GX86Id),
		DefaultNodeCount: 3,
		Priority:         0,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
		Conditions: []*globaldedicatedv1.Sku_Condition{
			{
				Key:      globaldedicatedv1.Sku_Condition_ATTACH_TIERUNIT,
				Operator: globaldedicatedv1.Sku_Condition_IN,
				Values: []string{
					"tikv-8c8g-x86-data:gp3-raft:none-fixed",
				},
			},
		},
	})
	if err != nil {
		return err
	}
	// 7c7g
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "pd-7c7g-arm-data:gp3-dynamic",
		SpuId:            spuPd7C7G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_PD,
		InstanceMuId:     uint64(instance7C7GArmId),
		DefaultNodeCount: 3,
		Priority:         0,
		DataStorage: &globaldedicatedv1.Sku_Storage{
			StorageMuId:   uint64(gp3Id),
			SizeGiDefault: 1,
			SizeGiMin:     1,
			SizeGiMax:     999999999,
			IopsMax:       999,
			IopsMin:       1,
			Iops: &globaldedicatedv1.Sku_Storage_IopsDynamic_{
				IopsDynamic: &globaldedicatedv1.Sku_Storage_IopsDynamic{
					IopsPerSizeGi: 2,
				},
			},
			ThroughputMibpsMax: 999,
			ThroughputMibpsMin: 1,
			Throughput: &globaldedicatedv1.Sku_Storage_ThroughputDynamic_{
				ThroughputDynamic: &globaldedicatedv1.Sku_Storage_ThroughputDynamic{
					ThroughputMibpsPerSizeGi: 0.5,
					ThroughputMibpsPerIops:   0.05,
				},
			},
		},
		Conditions: []*globaldedicatedv1.Sku_Condition{
			{
				Key:      globaldedicatedv1.Sku_Condition_ATTACH_TIERUNIT,
				Operator: globaldedicatedv1.Sku_Condition_IN,
				Values: []string{
					"tikv-2c2g-arm-data:gp3-raft:none-fixed",
				},
			},
		},
	})
	if err != nil {
		return err
	}

	// tiproxy spu.
	spuTiproxy8C8G, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "8c8g",
		Name:          "8c8g",
		ComponentType: globaldedicatedv1.ComponentType_TIPROXY,
		CpuCore:       8,
		MemorySizeGi:  8,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tiproxy-8c8g-arm",
			},
		},
	})
	if err != nil {
		return err
	}

	spuTiproxy2c2g, err := spuSvc.Create(ctx, &entity.Spu{
		DisplayName:   "2c2g",
		Name:          "2c2g",
		ComponentType: globaldedicatedv1.ComponentType_TIPROXY,
		CpuCore:       2,
		MemorySizeGi:  2,
		Mappings: []*globaldedicatedv1.Spu_Mapping{
			{
				CloudProvider:   globalcommonv1.CloudProvider_AWS,
				PhysicalRegions: []globalcommonv1.Region_Name{globalcommonv1.Region_AWS_US_WEST_2},
				OrganizationIds: []uint64{0},
				SkuKey:          "tiproxy-2c2g-arm",
			},
		},
	})
	if err != nil {
		return err
	}

	// tiproxy sku.
	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tiproxy-8c8g-arm",
		SpuId:            spuTiproxy8C8G.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIPROXY,
		InstanceMuId:     uint64(instance8C8GArmId),
		DefaultNodeCount: 2,
		Priority:         0,
	})
	if err != nil {
		return err
	}

	_, err = skuRepo.Save(ctx, &entity.Sku{
		Key:              "tiproxy-2c2g-arm",
		SpuId:            spuTiproxy2c2g.GetId(),
		CloudProvider:    globalcommonv1.CloudProvider_AWS,
		ComponentType:    globaldedicatedv1.ComponentType_TIPROXY,
		InstanceMuId:     uint64(instance2C2GArmId),
		DefaultNodeCount: 2,
		Priority:         0,
	})
	if err != nil {
		return err
	}

	return nil
}

func initDBCidrRecord(ctx context.Context, d pkgv2db.Provider) error {
	if err := d.WriteDB(ctx).Create(&schema.Cidr{
		Model: gorm.Model{
			ID: CidrID,
		},
		ProjectID:  ProjectID,
		RegionID:   uint64(getRegion(ctx, d).ID),
		Region:     nil,
		CIDR:       "172.16.0.0/19",
		ProviderID: uint64(getProvider(ctx, d).ID),
		Provider:   nil,
	}).Error; err != nil {
		return err
	}

	if err := d.WriteDB(ctx).Create(&schema.Cidr{
		Model: gorm.Model{
			ID: CidrID + 11,
		},
		ProjectID:  ProjectID,
		RegionID:   uint64(getGcpRegion(ctx, d).ID),
		Region:     nil,
		CIDR:       "10.16.0.0/19",
		ProviderID: uint64(getGcpProvider(ctx, d).ID),
		Provider:   nil,
	}).Error; err != nil {
		return err
	}

	return nil
}

func getGcpRegion(ctx context.Context, d pkgv2db.Provider) *schema.Region {
	var region schema.Region
	err := d.ReadDB(ctx).
		Model(&schema.Region{}).
		Where("name=?", globalcommonv1.Region_GCP_US_WEST1.String()).
		First(&region).
		Error
	if err != nil {
		tilog.Error(ctx, "query region failed", zap.Error(err))
		panic(err)
	}

	return &region
}

func getGcpProvider(ctx context.Context, d pkgv2db.Provider) *schema.Provider {
	var provider schema.Provider
	err := d.ReadDB(ctx).
		Model(&schema.Provider{}).
		Where("name=?", globalcommonv1.CloudProvider_GCP.String()).
		First(&provider).
		Error
	if err != nil {
		tilog.Error(ctx, "query provider failed", zap.Error(err))
		panic(err)
	}

	return &provider
}

func getRegion(ctx context.Context, d pkgv2db.Provider) *schema.Region {
	var region schema.Region
	err := d.ReadDB(ctx).
		Model(&schema.Region{}).
		Where("name=?", globalcommonv1.Region_AWS_US_WEST_2.String()).
		First(&region).
		Error
	if err != nil {
		tilog.Error(ctx, "query region failed", zap.Error(err))
		panic(err)
	}

	return &region
}

func getProvider(ctx context.Context, d pkgv2db.Provider) *schema.Provider {
	var provider schema.Provider
	err := d.ReadDB(ctx).
		Model(&schema.Provider{}).
		Where("name=?", globalcommonv1.CloudProvider_AWS.String()).
		First(&provider).
		Error
	if err != nil {
		tilog.Error(ctx, "query provider failed", zap.Error(err))
		panic(err)
	}

	return &provider
}
