package integration

import (
	"testing"

	"github.com/tidbcloud/metrics-integration/global/internal/domain/entity"
)

func TestNormalizeIntegrationCloudProviderType(t *testing.T) {
	tests := []struct {
		name     string
		provider string
		want     entity.IntegrationCloudProviderType
		wantErr  bool
	}{
		{name: "aws lowercase", provider: "aws", want: entity.IntegrationCloudProviderTypeAWS},
		{name: "aws enum", provider: "AWS", want: entity.IntegrationCloudProviderTypeAWS},
		{name: "gcp lowercase", provider: "gcp", want: entity.IntegrationCloudProviderTypeGCP},
		{name: "gcp enum", provider: "GCP", want: entity.IntegrationCloudProviderTypeGCP},
		{name: "azure lowercase", provider: "azure", want: entity.IntegrationCloudProviderTypeAzure},
		{name: "azure enum", provider: "AZURE", want: entity.IntegrationCloudProviderTypeAzure},
		{name: "alicloud lowercase", provider: "alicloud", want: entity.IntegrationCloudProviderTypeAlibabaCloud},
		{name: "alibaba cloud enum", provider: "ALIBABACLOUD", want: entity.IntegrationCloudProviderTypeAlibabaCloud},
		{name: "aliyun alias", provider: "aliyun", want: entity.IntegrationCloudProviderTypeAlibabaCloud},
		{name: "local", provider: "local", want: entity.IntegrationCloudProviderTypeLocal},
		{name: "unsupported", provider: "oracle", wantErr: true},
		{name: "empty", provider: "", wantErr: true},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := normalizeIntegrationCloudProviderType(tt.provider)
			if tt.wantErr {
				if err == nil {
					t.Fatal("normalizeIntegrationCloudProviderType() error = nil, want error")
				}
				return
			}
			if err != nil {
				t.Fatalf("normalizeIntegrationCloudProviderType() error = %v", err)
			}
			if got != tt.want {
				t.Fatalf("normalizeIntegrationCloudProviderType() = %q, want %q", got, tt.want)
			}
		})
	}
}
