package utils

import (
	"testing"

	"github.com/stretchr/testify/assert"
	commonv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/common/v1"
	nextgenv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/nextgen/v1"
	mgmt "github.com/tidbcloud/tidb-management-service/api/spec/tidb_mgmt_service/v1"
)

func TestGetServicePlan(t *testing.T) {
	testcases := []struct {
		name         string
		cluster      *mgmt.Cluster
		expectedPlan commonv1.ServicePlan
	}{
		{
			name: "service plan byoc",
			cluster: &mgmt.Cluster{
				ClusterInfo: &mgmt.Cluster_NextGenCluster{
					NextGenCluster: &nextgenv1.Cluster{
						ServicePlan: commonv1.ServicePlan_BYOC,
					},
				},
			},
			expectedPlan: commonv1.ServicePlan_BYOC,
		},
		{
			name: "service plan dedicated",
			cluster: &mgmt.Cluster{
				ClusterInfo: &mgmt.Cluster_NextGenCluster{
					NextGenCluster: &nextgenv1.Cluster{
						ServicePlan: commonv1.ServicePlan_Premium,
					},
				},
			},
			expectedPlan: commonv1.ServicePlan_Premium,
		},
		{
			name: "nil nextgen cluster",
			cluster: &mgmt.Cluster{
				ClusterInfo: nil,
			},
			expectedPlan: commonv1.ServicePlan_SERVICE_PLAN_UNSPECIFIED,
		},
	}

	for _, tc := range testcases {
		t.Run(tc.name, func(t *testing.T) {
			wrapper := NewCluster(tc.cluster)
			assert.Equal(t, tc.expectedPlan, wrapper.GetServicePlan())
		})
	}
}
