#!/usr/bin/env python3
"""Backfill WARDEN-WP-0012 gated routing scenarios as demand-weighted suggestions."""
from __future__ import annotations

import os
import sys

import httpx

API_BASE = os.getenv("STATE_HUB_URL", "http://127.0.0.1:8000")

SCENARIOS = [
    ("issue-core-ingestion-api-key", "Issue-core ingestion API key OpenBao path"),
    ("activity-core-issue-sink", "Activity-core issue sink consumer key custody"),
    ("openrouter-llm-connect", "OpenRouter llm-connect OpenBao → K8s Secret path"),
    ("object-storage-sts", "Object storage STS vending path (NK-WP-0007)"),
    ("human-oidc-login", "Human OIDC login via key-cape / Keycloak"),
    ("flex-auth-resource-check", "flex-auth policy decision before sensitive action"),
    ("host-principal-deploy", "auth_principals sync for host principal deploy"),
]


def main() -> int:
    created = 0
    with httpx.Client(base_url=API_BASE, timeout=30.0) as client:
        health = client.get("/state/health")
        health.raise_for_status()
        existing = {
            item.get("origin_ref")
            for item in client.get("/suggestions/", params={"include_terminal": True}).json()
        }
        for origin_ref, title in SCENARIOS:
            if origin_ref in existing:
                continue
            resp = client.post("/suggestions/", json={
                "domain": os.getenv("SUGGESTION_DOMAIN", "infotech"),
                "title": title,
                "description": (
                    "Gated routing scenario from WARDEN-WP-0012. Owner path not yet "
                    "shipped; accrues relevance when agents hit this unmet need."
                ),
                "origin": "WARDEN-WP-0012",
                "origin_ref": origin_ref,
                "base_value": 4.0,
                "job_size": 3.0,
            })
            resp.raise_for_status()
            created += 1
            print(f"created {origin_ref}")
    print(f"done: {created} new suggestions")
    return 0


if __name__ == "__main__":
    sys.exit(main())