package service

import (
	"os"
	"testing"
)

// TestAIService_Initialization verifies that the AIService parses environment variables
// correctly and initializes the required fallback strategies and default settings.
func TestAIService_Initialization(t *testing.T) {
	// Temporarily set testing ENVs to avoid depending on local .env
	os.Setenv("LLM_PROVIDER", "anthropic")
	os.Setenv("LLM_MODEL", "claude-3-5-haiku-latest")
	os.Setenv("OPENAI_API_KEY", "test-key-openai")
	defer os.Clearenv() // Clean up after test

	svc := NewAIService()
	if svc == nil {
		t.Fatal("Expected AIService to be initialized, got nil")
	}

	if svc.defaultProvider != "anthropic" {
		t.Errorf("Expected default provider 'anthropic', got '%s'", svc.defaultProvider)
	}

	if svc.defaultModel != "claude-3-5-haiku-latest" {
		t.Errorf("Expected default model 'claude-3-5-haiku-latest', got '%s'", svc.defaultModel)
	}

	// Verify that OpenAI provider was initialized because OPENAI_API_KEY was present
	_, hasOpenAI := svc.providers["openai"]
	if !hasOpenAI {
		t.Error("Expected OpenAI provider to be initialized, but it was not found")
	}

	// Verify that circuit breakers were initialized
	_, hasBreaker := svc.breakers["openai"]
	if !hasBreaker {
		t.Error("Expected circuit breaker for setup provider, but it was not found")
	}
}
