#!/usr/bin/env herodo
// Basic HTTP Route Configuration
// This example shows how to create a simple HTTP route with Traefik

let namespace = "production";

// Create a KubernetesManager for the namespace
let km = kubernetes(namespace);
print(`Connected to namespace: ${namespace(km)}`);

// ============================================
// Create a basic HTTP route
// ============================================

// Build the HTTP route with fluent API
let route = http_route("my-app-route", namespace)
    .hostname("app.example.com")
    .service("my-app-service", 8080)
    .build();

print(`Created HTTP route: ${route.name}`);
print(`Namespace: ${route.namespace}`);

// Print the generated YAML
print("\n--- Generated IngressRoute YAML ---");
print(to_yaml(route));

// Print the generated JSON
print("\n--- Generated IngressRoute JSON ---");
print(to_json(route));

// ============================================
// Create a route with path prefix
// ============================================

let api_route = http_route("api-route", namespace)
    .hostname("api.example.com")
    .path_prefix("/v1")
    .service("api-service", 3000)
    .build();

print("\n--- API Route with Path Prefix ---");
print(to_yaml(api_route));

// ============================================
// Create a route with TLS (Let's Encrypt)
// ============================================

let secure_route = http_route("secure-app", namespace)
    .hostname("secure.example.com")
    .service("secure-service", 443)
    .tls_letsencrypt("letsencrypt")
    .build();

print("\n--- Secure Route with Let's Encrypt TLS ---");
print(to_yaml(secure_route));

// ============================================
// Apply the route to the cluster
// ============================================

// Uncomment to apply:
// apply_http_route(km, route);
// print("Route applied successfully!");

// ============================================
// List existing routes
// ============================================

// let routes = list_http_routes(km, namespace);
// print(`\nExisting routes in ${namespace}:`);
// for r in routes {
//     print(`  - ${r}`);
// }
