package coresvccli

import (
	"context"
	"fmt"
	"testing"

	"github.com/tidbcloud/devops/pkg/infra/utils/test"
	commonv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/common/v1"
	mgmtv1 "github.com/tidbcloud/tidb-management-service/api/spec/tidb_mgmt_service/v1"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
)

func TestLarkClient(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Core Svc Client")
}

var _ = Describe("[Config Center Client]", func() {
	var cli *CoreSvcCli

	BeforeEach(func() {
		var err error

		cli, err = NewCoreSvcCli("127.0.0.1:1335", "127.0.0.1:1336", "127.0.0.1:1337")
		Expect(err).To(BeNil())
	})

	Context("Have a try", func() {

		Context("Dataplane", func() {

			PIt("GetCompatNetwork", func() {
				ctx := context.Background()
				clusterID := uint64(10981087791007091151)

				clusterInCS, err := cli.GetCluster(ctx, clusterID, true)
				Expect(err).To(BeNil())
				fmt.Println(test.MarshalIndentOrDie(clusterInCS))

				compatNetwork, err := cli.Mgmt.Dataplane.GetCompatNetwork(ctx, &mgmtv1.GetCompatNetworkRequest{
					ProjectId:    clusterInCS.ProjectId,
					ProviderName: clusterInCS.InfraProviderType,
					RegionName:   clusterInCS.RegionName,
				})
				Expect(err).To(BeNil())
				fmt.Println(test.MarshalIndentOrDie(compatNetwork))
			})

			PIt("GetCluster", func() {
				ctx := context.Background()
				clusterID := uint64(10593058150927443391)

				clusterInCS, err := cli.Mgmt.GetCluster(ctx, clusterID)
				Expect(err).To(BeNil())
				fmt.Println(test.MarshalIndentOrDie(clusterInCS))
			})

			PIt("GetCluster", func() {
				ctx := context.Background()

				clusterInCS, err := cli.Mgmt.Region.GetRegion(ctx, &mgmtv1.GetRegionRequest{
					DeployType:        mgmtv1.DeployType_DEPLOY_TYPE_SERVERLESS,
					CloudProviderId:   commonv1.CloudProvider_AWS,
					RegionLogicalName: "us-east-1",
					ServicePlan:       commonv1.ServicePlan_Starter,
				})
				Expect(err).To(BeNil())
				fmt.Println(test.MarshalIndentOrDie(clusterInCS))
			})
		})

	})
})
