#![cfg(feature = "_build")]

use std::env;
use std::path::{Path, PathBuf};

fn main() {
    let manifest_dir =
        env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR environment variable not set");
    let manifest_path = Path::new(&manifest_dir);

    let conjure_input: PathBuf = env::var("CONJURE_IR_PATH")
        .map(PathBuf::from)
        .unwrap_or_else(|_| {
            manifest_path.join("definitions/conjure/scout-service-api.conjure.json")
        });

    let conjure_output: PathBuf = env::var("CONJURE_OUT_DIR")
        .map(PathBuf::from)
        .unwrap_or_else(|_| manifest_path.join("src/conjure"));

    if !conjure_input.exists() {
        panic!("compile-conjure: {} not found; this is a bug with nominal-api", conjure_input.display());
    }

    std::fs::create_dir_all(&conjure_output).expect("Failed to create conjure output directory");

    conjure_codegen::Config::new()
        .strip_prefix("io.nominal".to_string())
        .generate_files(conjure_input, conjure_output)
        .unwrap();
}
