// Copyright (C) 2026 Ordinary Labs, LLC.
//
// SPDX-License-Identifier: AGPL-3.0-only

#[cfg(feature = "docs")]
mod jsonschema;

fn main() -> anyhow::Result<()> {
    #[cfg(feature = "docs")]
    {
        let schema = schemars::schema_for!(ordinary_config::OrdinaryConfig);
        let json = serde_json::to_string_pretty(&schema)?;
        let markdown = jsonschema::to_markdown(&schema)?;

        let generated_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("generated");
        std::fs::create_dir_all(&generated_dir)?;

        let docs_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("docs");
        std::fs::create_dir_all(&docs_dir)?;

        fs_err::write(generated_dir.join("config.schema.json"), json)?;
        fs_err::write(docs_dir.join("config-reference.md"), markdown)?;
    }

    Ok(())
}
