# KCL Dependency configuration for os taskserv
# Defines comprehensive dependency, resource, and health requirements

import provisioning.dependencies as schema

# OS taskserv dependency configuration
_dependencies = schema.TaskservDependencies {
    name = "os"

    # Base OS has no dependencies - it's the foundation
    requires = []

    # Optional enhancements - install if available
    optional = ["resolv", "ip-aliases", "proxy"]

    # No conflicts - OS is foundational
    conflicts = []

    # Services provided by this taskserv
    provides = ["base-os", "systemd", "networking", "package-manager", "filesystem"]

    # Resource requirements for OS configuration
    resources = schema.ResourceRequirement {
        cpu = "100m"            # Minimal CPU for OS operations
        memory = "128Mi"        # 128MB RAM minimum
        disk = "10Gi"          # 10GB minimum for OS and packages
        network = True          # Requires network for package updates
        privileged = True       # Needs full system access for OS configuration
    }

    # Health checks for OS components
    health_checks = [
        schema.HealthCheck {
            command = "systemctl is-system-running | grep -E 'running|degraded'"
            interval = 60
            timeout = 10
            retries = 2
            success_threshold = 1
            failure_threshold = 3
        },
        schema.HealthCheck {
            command = "df / | tail -1 | awk '{print $5}' | tr -d '%' | awk '$1 < 90'"
            interval = 300
            timeout = 5
            retries = 1
        },
        schema.HealthCheck {
            command = "free -m | awk 'NR==2{printf \"%.1f\", $3*100/$2 }' | awk '$1 < 95'"
            interval = 120
            timeout = 5
            retries = 2
        }
    ]

    # Readiness probe for installation completion
    readiness_probe = schema.HealthCheck {
        command = "systemctl list-failed | grep -q '0 loaded units listed' || systemctl list-failed --state=failed | wc -l | grep -q '^0$'"
        interval = 30
        timeout = 10
        retries = 5
        success_threshold = 2
    }

    # Installation phases for ordered deployment
    phases = [
        schema.InstallationPhase {
            name = "pre-install"
            order = 1
            parallel = False
            required = True
        },
        schema.InstallationPhase {
            name = "install"
            order = 2
            parallel = True          # OS updates can run in parallel
            required = True
        },
        schema.InstallationPhase {
            name = "post-install"
            order = 3
            parallel = True
            required = True
        },
        schema.InstallationPhase {
            name = "validate"
            order = 4
            parallel = False
            required = True
        }
    ]

    # Installation control
    timeout = 900               # 15 minutes for OS updates and configuration
    retry_count = 2             # Conservative retry for OS operations

    # Platform compatibility - all supported platforms
    os_support = ["linux"]
    arch_support = ["amd64", "arm64"]
    k8s_versions = []           # OS doesn't depend on K8s versions
}

# Output for dynamic dependency resolution
_dependencies