# Simple validation functions for provisioning tool

export def check-required [
    value: any
    name: string
] {
    if ($value | is-empty) {
        print $"🛑 Required parameter '($name)' is missing or empty"
        return false
    }
    true
}

export def check-path [
    path: string
] {
    if ($path | is-empty) {
        print "🛑 Path parameter is empty"
        return false
    }
    true
}

export def check-path-exists [
    path: string
] {
    if not ($path | path exists) {
        print $"🛑 Path '($path)' does not exist"
        return false
    }
    true
}

export def check-command [
    command: string
] {
    let result = (^bash -c $"type -P ($command)" | complete)
    if $result.exit_code != 0 {
        print $"🛑 Command '($command)' not found in PATH"
        return false
    }
    true
}

export def safe-run [
    command: closure
    context: string
] {
    let result = (do $command | complete)
    if $result.exit_code != 0 {
        print $"⚠️  Warning: Error in ($context): ($result.stderr)"
        null
    } else {
        $result.stdout
    }
}
