package migrationcluster

import (
	"testing"

	globaldedicatedv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/dedicated/v1"
	openapicommonv1beta1 "github.com/tidbcloud/tidb-management-service/api/spec/tidb_cloud_open_api/common/v1beta1"
	tidbmgmtservicev1 "github.com/tidbcloud/tidb-management-service/api/spec/tidb_mgmt_service/v1"
	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-service/domain/entity"
)

func TestBuildCluster(t *testing.T) {
	t.Parallel()

	t.Run("migration cluster should have ServicePlan_Dedicated", func(t *testing.T) {
		sourceCluster := &entity.Cluster{
			ClusterId:      100,
			ProjectId:      1,
			OrganizationId: 2,
			CloudProvider:  openapicommonv1beta1.Region_aws,
			Region:         "us-east-1",
			UserId:         "user-123",
			CreatedBy:      "user@example.com",
			DeployType:     entity.DeployTypeDedicated,
		}

		globalTargetCluster := &globaldedicatedv1.Cluster{
			ClusterId:      200,
			ProjectId:      1,
			OrganizationId: 2,
		}

		req := &tidbmgmtservicev1.CreateMigrationClusterRequest{
			MigrationCluster: &tidbmgmtservicev1.MigrationCluster{
				ClusterDisplayName: "migration-cluster",
			},
		}

		result := buildCluster(req, sourceCluster, globalTargetCluster)

		if result.ServicePlan != openapicommonv1beta1.ServicePlan_Dedicated {
			t.Errorf("ServicePlan = %v, want %v", result.ServicePlan, openapicommonv1beta1.ServicePlan_Dedicated)
		}
		if result.DeployType != entity.DeployTypeDedicated {
			t.Errorf("DeployType = %v, want %v", result.DeployType, entity.DeployTypeDedicated)
		}
	})
}
