package main

import (
	"fmt"
	"log"

	"github.com/deb-bootc-image-builder/bib/internal/config"
)

// This is an example of how the configuration system would be used
// in the actual debian-bootc-image-builder application

func main() {
	// Load configuration from the default location
	cfg, err := config.LoadConfig("")
	if err != nil {
		log.Fatalf("Failed to load configuration: %v", err)
	}

	// Example 1: Get the active registry information
	registry, err := cfg.GetActiveRegistry()
	if err != nil {
		log.Fatalf("Failed to get active registry: %v", err)
	}
	fmt.Printf("Active registry: %s (%s)\n", cfg.ActiveRegistry, registry.Description)
	fmt.Printf("Base URL: %s\n", registry.BaseURL)
	fmt.Printf("Namespace: %s\n", registry.Namespace)
	fmt.Printf("Auth required: %v\n", registry.AuthRequired)

	// Example 2: Generate container names
	bootcBaseName, err := cfg.GetBootcBaseName("stable")
	if err != nil {
		log.Fatalf("Failed to generate bootc base name: %v", err)
	}
	fmt.Printf("Bootc base container: %s\n", bootcBaseName)

	bootcBuilderName, err := cfg.GetBootcBuilderName("latest")
	if err != nil {
		log.Fatalf("Failed to generate bootc builder name: %v", err)
	}
	fmt.Printf("Bootc builder container: %s\n", bootcBuilderName)

	// Example 3: Get Debian version mapping
	actualVersion, err := cfg.GetDebianVersion("stable")
	if err != nil {
		log.Fatalf("Failed to get Debian version: %v", err)
	}
	fmt.Printf("Debian stable maps to: %s\n", actualVersion)

	// Example 4: Get default settings
	fmt.Printf("Default Debian version: %s\n", cfg.Defaults.DebianVersion)
	fmt.Printf("Default image types: %v\n", cfg.Defaults.ImageTypes)
	fmt.Printf("Default output directory: %s\n", cfg.Defaults.OutputDir)
	fmt.Printf("Default rootfs type: %s\n", cfg.Defaults.RootfsType)

	// Example 5: Check experimental features
	fmt.Printf("Cross-arch support enabled: %v\n", cfg.IsExperimentalFeatureEnabled("cross_arch"))
	fmt.Printf("Librepo support enabled: %v\n", cfg.IsExperimentalFeatureEnabled("librepo"))

	// Example 6: Get repository information
	mainRepoURL, err := cfg.GetRepositoryURL("main")
	if err != nil {
		log.Fatalf("Failed to get main repository URL: %v", err)
	}
	fmt.Printf("Main repository URL: %s\n", mainRepoURL)
	fmt.Printf("Main repository priority: %d\n", cfg.GetRepositoryPriority("main"))

	// Example 7: Get build settings
	fmt.Printf("Container size multiplier: %d\n", cfg.Build.ContainerSizeMultiplier)
	fmt.Printf("Minimum rootfs size: %d GB\n", cfg.Build.MinRootfsSizeGB)

	// Example 8: Get cloud settings
	fmt.Printf("Default AWS region: %s\n", cfg.Cloud.AWS.DefaultRegion)
	fmt.Printf("S3 bucket template: %s\n", cfg.Cloud.AWS.BucketTemplate)

	// Example 9: Get logging settings
	fmt.Printf("Log level: %s\n", cfg.Logging.Level)
	fmt.Printf("Log format: %s\n", cfg.Logging.Format)
	fmt.Printf("Verbose mode: %v\n", cfg.Logging.Verbose)

	// Example 10: Get security settings
	fmt.Printf("Require HTTPS: %v\n", cfg.Security.RequireHTTPS)
	fmt.Printf("Verify TLS: %v\n", cfg.Security.VerifyTLS)
	fmt.Printf("Allow insecure: %v\n", cfg.Security.AllowInsecure)
}

// Example of how this would be integrated into the main application:

func exampleIntegration() {
	// Load configuration
	cfg, err := config.LoadConfig("")
	if err != nil {
		log.Fatalf("Failed to load configuration: %v", err)
	}

	// Use configuration in the build process
	imgref, err := cfg.GetBootcBaseName(cfg.Defaults.DebianVersion)
	if err != nil {
		log.Fatalf("Failed to generate image reference: %v", err)
	}

	// Use default settings
	outputDir := cfg.Defaults.OutputDir
	imageTypes := cfg.Defaults.ImageTypes
	rootfsType := cfg.Defaults.RootfsType

	// Check experimental features
	useLibrepo := cfg.IsExperimentalFeatureEnabled("librepo")
	crossArch := cfg.IsExperimentalFeatureEnabled("cross_arch")

	fmt.Printf("Building image: %s\n", imgref)
	fmt.Printf("Output directory: %s\n", outputDir)
	fmt.Printf("Image types: %v\n", imageTypes)
	fmt.Printf("Rootfs type: %s\n", rootfsType)
	fmt.Printf("Use librepo: %v\n", useLibrepo)
	fmt.Printf("Cross-arch: %v\n", crossArch)

	// The actual build process would continue here...
}
