// content-graph feature — build.rs integration snippet.
//
// Add this block to the implementation's server/build.rs (or as a separate
// build step) after sourcing the required environment variables.
//
// Required .env entries (add to foundation/.env):
//
//   CONTENT_GRAPH_CONTENT_DIR=site/content
//   CONTENT_GRAPH_NICKEL_SCHEMA_DIR=rustelo/nickel
//   CONTENT_GRAPH_FRAMEWORK_ONTOLOGY=/abs/path/to/rustelo/.ontology/core.ncl
//   CONTENT_GRAPH_IMPL_ONTOLOGY=.ontology/core.ncl
//   CONTENT_GRAPH_FRAMEWORK_ADRS_GLOB=/abs/path/to/rustelo/adrs/adr-*.ncl
//   CONTENT_GRAPH_IMPL_ADRS_GLOB=adrs/adr-*.ncl
//   ONTOREF_NICKEL_IMPORT_PATH=/abs/path/to/ontoref/ontology

fn generate_content_graph() {
    use content_graph::build::{codegen, graph_generator::GraphGeneratorConfig};

    let config = GraphGeneratorConfig::from_env()
        .expect("content-graph: missing required environment variables — see templates/build_rs_snippet.rs");

    let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());

    let graph = graph_generator::generate(&config)
        .expect("content-graph: graph generation failed");

    codegen::write_outputs(&graph, &out_dir)
        .expect("content-graph: codegen write failed");

    // Invalidate when any ontology or ADR file changes
    println!("cargo:rerun-if-env-changed=CONTENT_GRAPH_CONTENT_DIR");
    println!("cargo:rerun-if-env-changed=ONTOREF_NICKEL_IMPORT_PATH");
    println!("cargo:rerun-if-changed={}", config.framework_ontology.display());
    println!("cargo:rerun-if-changed={}", config.impl_ontology.display());
}
