#!/usr/bin/env nu
# export-config.nu - Export deployment configuration as environment variables
#
# Generated by: provctl gen deployment
# Generated at: 2025-11-20
#
# Exports deployment configuration from KCL as environment variables
# Usage:
#   source export-config.nu
#   echo $env.DEPLOYMENT_PROJECT_NAME
#   echo $env.ENABLED_SERVICES

# Project information
export-env {
    $env.DEPLOYMENT_PROJECT_NAME = "myproject"
    $env.DEPLOYMENT_PROJECT_VERSION = "1.0.0"
    $env.DEPLOYMENT_PROJECT_DESCRIPTION = "y"
}

# Enabled services
export-env {
    $env.SERVICE_CLI_ENABLED = "false"
}
export-env {
    $env.SERVICE_TUI_ENABLED = "false"
}
export-env {
    $env.SERVICE_API_ENABLED = "false"
}
export-env {
    $env.SERVICE_DASHBOARD_ENABLED = "false"
}

# Database configuration
export-env {
    $env.DATABASE_DEFAULT = "sqlite"
    $env.SUPPORTED_DATABASES = []  # Populated by deployment configuration
}
export-env {
    $env.DATABASE_SQLITE_ENABLED = "false"
}
export-env {
    $env.DATABASE_POSTGRES_ENABLED = "false"
}
export-env {
    $env.DATABASE_MYSQL_ENABLED = "false"
}
export-env {
    $env.DATABASE_SURREALDB_ENABLED = "false"
}

# Cache configuration
export-env {
    $env.CACHE_ENABLED = "false"
}

# Deployment presets
export-env {
    $env.AVAILABLE_PRESETS = [
        "n"
    ]
    $env.DEFAULT_PRESET = "dev"
}

# Helper functions for common operations

# List all enabled services
def services [] {
    """List all enabled services in this deployment"""
    [
        {
            name: "myproject-cli"
            type: "cli"
            requires: []
        }
        ,
        {
            name: "myproject-dashboard"
            type: "web"
            requires: ["api"]
        }
    ]
}

# List all configured databases
def databases [] {
    """List all configured database backends"""
    [
        {
            type: "sqlite"
            host: ""
            port: ""
            path: "/var/lib/myproject/db.sqlite"
        }
    ]
}

# List all deployment presets
def presets [] {
    """List all available deployment presets"""
    [
        {
            name: "n"
        }
    ]
}

# Print deployment summary
def summary [] {
    """Print a summary of this deployment configuration"""
    print $"Project: myproject v1.0.0"
    print $"Description: y"
    print ""
    print "Enabled Services:"
    services | each { |svc|
        if $svc.port != null {
            print $"  - ($svc.name) [$svc.type]:($svc.port)"
        } else {
            print $"  - ($svc.name) [$svc.type]"
        }
    }
    print ""
    print "Databases:"
    databases | each { |db|
        if $db.host != null {
            print $"  - ($db.type) (($db.host):($db.port))"
        } else if $db.path != null {
            print $"  - ($db.type) (($db.path))"
        } else {
            print $"  - ($db.type)"
        }
    }
    print ""
    print "Available Presets:"
    presets | each { |preset|
        print $"  - ($preset.name): ($preset.description)"
    }
}

# Export for easy access
export def services [] {
    """List all enabled services in this deployment"""
    services
}

export def databases [] {
    """List all configured database backends"""
    databases
}

export def presets [] {
    """List all available deployment presets"""
    presets
}

export def summary [] {
    """Print a summary of this deployment configuration"""
    summary
}

# Print summary when sourced
print "Deployment configuration loaded: myproject"
print "Run 'summary' to see deployment overview"
