//! Generate `schemas/compliance-rules.json` from `compliance/registry.yml`.
//!
//! The registry YAML is the source of truth; this emits the JSON catalog that
//! the repo commits, so consumers can cite a stable, machine-readable rule list
//! without parsing YAML. Run from the repo root:
//!
//! ```sh
//! cargo run -p mcptest-core --bin gen-compliance-catalog
//! ```
//!
//! The `catalog_json_is_in_sync_with_registry` test fails if the committed file
//! drifts from the registry, so a rule cannot be added without regenerating.

use std::path::PathBuf;

use mcptest_core::compliance::RuleRegistry;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let registry_path = std::env::args()
        .nth(1)
        .map(PathBuf::from)
        .unwrap_or_else(|| PathBuf::from("compliance/registry.yml"));
    let out_path = std::env::args()
        .nth(2)
        .map(PathBuf::from)
        .unwrap_or_else(|| PathBuf::from("schemas/compliance-rules.json"));

    let registry = RuleRegistry::load(&registry_path)?;
    let json = serde_json::to_string_pretty(&registry)?;
    std::fs::write(&out_path, format!("{json}\n"))?;
    eprintln!(
        "wrote {} ({} rules)",
        out_path.display(),
        registry.rules.len()
    );
    Ok(())
}
