package gcs

import (
	"testing"
)

func TestSanitizeForGCP(t *testing.T) {
	tests := []struct {
		input    string
		expected string
	}{
		{"my-project", "my-project"},
		{"My_Project", "my-project"},
		{"test@123", "test-123"},
		{"--edge--", "edge"},
		{"UPPERCASE", "uppercase"},
		{"spaces and stuff", "spaces-and-stuff"},
		{"special!@#$%chars", "special-chars"},
	}

	for _, tt := range tests {
		t.Run(tt.input, func(t *testing.T) {
			result := sanitizeForGCP(tt.input)
			if result != tt.expected {
				t.Errorf("sanitizeForGCP(%q) = %q, want %q", tt.input, result, tt.expected)
			}
		})
	}
}

func TestBucketNameFor(t *testing.T) {
	p := &Provisioner{}
	tests := []struct {
		projectID string
		expected  string
	}{
		{"my-app", "project-my-app-media"},
		{"Test_App", "project-test-app-media"},
		{"app123", "project-app123-media"},
	}

	for _, tt := range tests {
		t.Run(tt.projectID, func(t *testing.T) {
			result := p.bucketNameFor(tt.projectID)
			if result != tt.expected {
				t.Errorf("bucketNameFor(%q) = %q, want %q", tt.projectID, result, tt.expected)
			}
		})
	}
}

func TestServiceAccountEmailFor(t *testing.T) {
	p := &Provisioner{
		gcpProjectID: "threesix-prod",
	}
	tests := []struct {
		projectID string
		expected  string
	}{
		{"my-app", "project-my-app-storage@threesix-prod.iam.gserviceaccount.com"},
		{"Test_App", "project-test-app-storage@threesix-prod.iam.gserviceaccount.com"},
	}

	for _, tt := range tests {
		t.Run(tt.projectID, func(t *testing.T) {
			result := p.serviceAccountEmailFor(tt.projectID)
			if result != tt.expected {
				t.Errorf("serviceAccountEmailFor(%q) = %q, want %q", tt.projectID, result, tt.expected)
			}
		})
	}
}
