package aks

import (
	"testing"

	"github.com/tidbcloud/eks-provider/controllers/cluster/task"
	cloudv1 "github.com/tidbcloud/infra-api/api/v1"
)

func TestGetAKSLoadBalancerResourceID(t *testing.T) {
	tests := []struct {
		name        string
		svcUID      string
		isPrivateLB bool
		expected    string
	}{
		{
			name:        "Public Load Balancer",
			svcUID:      "cf07ffb8-ce03-46d3-9ee1-73a529ebfbfc",
			isPrivateLB: false,
			expected:    "/subscriptions/test-subscription/resourceGroups/test-resource-group/providers/Microsoft.Network/loadBalancers/kubernetes/frontendIPConfigurations/acf07ffb8ce0346d39ee173a529ebfbf",
		},
		{
			name:        "Private Load Balancer",
			svcUID:      "cf07ffb8-ce03-46d3-9ee1-73a529ebfbfc",
			isPrivateLB: true,
			expected:    "/subscriptions/test-subscription/resourceGroups/test-resource-group/providers/Microsoft.Network/loadBalancers/kubernetes-internal/frontendIPConfigurations/acf07ffb8ce0346d39ee173a529ebfbf",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			service :=
				&Service{
					BaseTask: &task.BaseTask{
						Context: &task.Context{
							Cluster: &cloudv1.Cluster{
								Spec: cloudv1.ClusterSpec{
									Kubernetes: cloudv1.Kubernetes{
										Account: "test-subscription",
										Cloud: cloudv1.Cloud{
											Azure: &cloudv1.CloudAzure{
												NodeResourceGroup: "test-resource-group",
											},
										},
									},
								},
							},
						},
					},
				}
			got := service.getAKSLoadBalancerResourceID(tt.svcUID, tt.isPrivateLB)
			if got != tt.expected {
				t.Errorf("getAKSLoadBalancerResourceID() = %v, want %v", got, tt.expected)
			}
		})
	}
}
