package privateendpoint

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	globalngv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/nextgen/v1"
	openapingv1beta2 "github.com/tidbcloud/tidb-management-service/api/spec/tidb_cloud_open_api/nextgen/v1beta2"
)

func TestBuildGlobalCreatePrivateLinkConnectionRequest(t *testing.T) {
	openAPIReq := &openapingv1beta2.CreatePrivateEndpointConnectionRequest{
		TidbId: "1001",
		PrivateEndpointConnection: &openapingv1beta2.PrivateEndpointConnection{
			EndpointId:        "/subscriptions/sub-1/resourceGroups/rg/providers/Microsoft.Network/privateEndpoints/pe-1",
			PrivateIpAddress:  "10.0.1.4",
			PrivateDomainName: "private.example.aliyun.com",
		},
	}

	globalReq := buildGlobalCreatePrivateLinkConnectionRequest(1001, openAPIReq)
	require.NotNil(t, globalReq)
	require.NotNil(t, globalReq.GetPrivateLinkConnection())

	assert.EqualValues(t, 1001, globalReq.GetClusterId())
	assert.Equal(t, openAPIReq.GetPrivateEndpointConnection().GetEndpointId(), globalReq.GetPrivateLinkConnection().GetEndpointId())
	assert.Equal(t, openAPIReq.GetPrivateEndpointConnection().GetPrivateIpAddress(), globalReq.GetPrivateLinkConnection().GetPrivateIpAddress())
	assert.Equal(t, openAPIReq.GetPrivateEndpointConnection().GetPrivateDomainName(), globalReq.GetPrivateLinkConnection().GetPrivateDomainName())
	assert.Equal(t, globalngv1.PrivateLinkConnection_CUSTOMER, globalReq.GetPrivateLinkConnection().GetEndpointType())
}
