use std::env;
use std::path::Path;

fn main() {
    let conjure_input =
        Path::new("definitions/conjure/scout-service-api.conjure.json").to_path_buf();
    println!("cargo:rerun-if-changed={}", conjure_input.display());

    let conjure_output = Path::new(&env::var_os("OUT_DIR").unwrap()).join("conjure");

    // Check if conjure.json file exists
    if !conjure_input.exists() {
        panic!(
            "\n===\nConjure definition file '{}' not found. Run `./gradlew :scout-service-api-rust:prepareNominalApis` to copy the file to the definitions directory.\n===\n",
            conjure_input.display()
        );
    }

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