package main

import (
	"os"

	"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/adapters/driving/cli"
	"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/adapters/driven/edgeconnect"
	"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/core/services"
)

func main() {
	// Präsentationsschicht: Simple dependency wiring - no complex container needed
	
	// 1. Infrastructure Layer: Create EdgeConnect client (concrete implementation)
	baseURL := getEnvOrDefault("EDGE_CONNECT_BASE_URL", "https://console.mobiledgex.net")
	username := os.Getenv("EDGE_CONNECT_USERNAME")
	password := os.Getenv("EDGE_CONNECT_PASSWORD")
	
	var client *edgeconnect.Client
	if username != "" && password != "" {
		client = edgeconnect.NewClientWithCredentials(baseURL, username, password)
	} else {
		client = edgeconnect.NewClient(baseURL)
	}
	
	// 2. Application Layer: Create services with dependency injection (client implements repository interfaces)
	appService := services.NewAppService(client)           // client implements AppRepository
	instanceService := services.NewAppInstanceService(client) // client implements AppInstanceRepository  
	cloudletService := services.NewCloudletService(client)    // client implements CloudletRepository
	
	// 3. Presentation Layer: Execute CLI driven adapters with injected services (simple parameter passing)
	cli.ExecuteWithServices(appService, instanceService, cloudletService)
}

func getEnvOrDefault(key, defaultValue string) string {
	if value := os.Getenv(key); value != "" {
		return value
	}
	return defaultValue
}
