# Platform Services Activation
# Integration point for validating and connecting to platform services during workspace activation

use target.nu *

# Activate platform services for workspace
export def activate-workspace-platform [
    workspace_name: string
    --auto-start
    --wait
    --skip-optional
] {
    print ""
    print $"🔌 Activating platform services for workspace: ($workspace_name)"
    print ""

    # Get workspace path from the workspace registry
    let workspace_path = (get-workspace-path $workspace_name)

    # Load and validate platform target configuration
    let platform_target_path = ([$workspace_path "config" "platform" "target.yaml"] | path join)

    if not ($platform_target_path | path exists) {
        print $"⚠️  Platform target configuration not found at: ($platform_target_path)"
        print "   Continuing without platform services"
        print ""
        return true
    }

    # Load the platform target configuration
    let platform = (open $platform_target_path)

    # Display platform information
    print $"Platform Type: ($platform.platform.type)"
    print $"Platform Mode: ($platform.platform.mode)"
    print ""

    # List enabled services
    let services = $platform.platform.services
    let enabled_services = (
        $services
        | columns
        | where {|svc| ($services | get $svc).enabled }
    )

    if ($enabled_services | is-empty) {
        print "No platform services enabled"
        print ""
        return true
    }

    print "Enabled Platform Services:"
    $enabled_services | each {|service|
        print $"  • ($service)"
    }
    print ""

    true
}
