package grpcli

import (
	"context"
	"fmt"
	"reflect"
	"testing"

	"github.com/stretchr/testify/suite"
	"github.com/tidbcloud/core-svc/idl/pbgen/proto/core"
	"github.com/tidbcloud/dataflow-service/internal/config"
	"github.com/tidbcloud/pkgv2/bizerr"
)

type grpcCLICoreSuite struct {
	suite.Suite
}

func TestGRPCCLICoreSuite(t *testing.T) {
	suite.Run(t, new(grpcCLICoreSuite))
}

func (s *grpcCLICoreSuite) TestListClustersReqOptions() {
	testCases := []struct {
		CaseName    string
		Option      ListClustersReqOption
		ExpectedReq *core.ListClustersReq
	}{
		{
			CaseName: "exclude deleted or cleared",
			Option:   ListClustersWithExcludeStatuses(DeletedOrClearedClusterStatus),
			ExpectedReq: &core.ListClustersReq{
				Filter: &core.ClusterFilter{
					ExcludeStatuses: DeletedOrClearedClusterStatus,
				},
			},
		},
		{
			CaseName: "include running status",
			Option:   ListClustersWithIncludeStatuses(RunningClusterStatus),
			ExpectedReq: &core.ListClustersReq{
				Filter: &core.ClusterFilter{
					Statuses: RunningClusterStatus,
				},
			},
		},
		{
			CaseName: "with dataplane info",
			Option:   ListClustersWithDataPlaneInfo(),
			ExpectedReq: &core.ListClustersReq{
				WithDataPlaneInfo: true,
			},
		},
	}
	for _, tc := range testCases {
		req := &core.ListClustersReq{}
		tc.Option(req)
		s.Require().Equalf(tc.ExpectedReq, req, "case: %s", tc.CaseName)
	}
}

func TestGetClusterConfidentialInfo(t *testing.T) {
	ctx := context.TODO()
	type args struct {
		req *core.GetClusterConfidentialInfoReq
	}
	tests := []struct {
		name  string
		args  args
		want1 bizerr.BizError
	}{
		{
			name: "OK",
			args: args{
				req: &core.GetClusterConfidentialInfoReq{
					ClusterId: 10091972636908134668,
				},
			},
			want1: nil,
		},
	}
	config.Global().GrpcConfig.CoreSvcAddr = "127.0.0.1:10102"
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, got1 := GetClusterConfidentialInfo(ctx, tt.args.req)
			if !reflect.DeepEqual(got1, tt.want1) {
				t.Errorf("GetClusterConfidentialInfo() got1 = %v, want %v", got1, tt.want1)
			}
			fmt.Println(got)
		})
	}
}
