// padlock-cli/src/commands/init.rs
//
// `padlock init` — generate a .padlock.toml template in the current directory.

use std::path::Path;

const TEMPLATE: &str = r#"# .padlock.toml — padlock project configuration
# Generated by `padlock init`. Uncomment and adjust the options you need.
# Documentation: https://github.com/gidotencate/padlock#configuration

[padlock]
# Minimum severity to report. Findings below this level are suppressed entirely.
# Options: "low" (default) | "medium" | "high"
# min_severity = "low"

# Exit with a non-zero status code if any struct scores below this value (0-100).
# 0 disables the threshold (default). Useful for CI ratcheting.
# fail_below = 0

# Struct names to suppress entirely from output and exit-code logic.
# ignore = ["GeneratedStruct", "FfiLayout"]

# ── Filter defaults (CLI flags override these when specified) ──────────────────

# Include only structs whose names match this regex pattern.
# filter = "^(Hot|Critical)"

# Exclude structs whose names match this regex pattern.
# exclude = "^Generated"

# Show only structs with total size >= N bytes.
# min_size = 64

# Show only structs with at least N padding holes.
# min_holes = 1

# Default sort order for output: "score" | "size" | "waste" | "name"
# sort_by = "score"

# Exit non-zero if any finding meets this severity: "high" | "medium" | "low"
# fail_on_severity = "high"

[arch]
# Force a specific architecture for layout simulation.
# Options: x86_64 (default) | aarch64 | aarch64_apple | wasm32 | riscv64
# override = "x86_64"

# ── Per-struct overrides ───────────────────────────────────────────────────────
# Override min_severity or fail_below for a specific struct by name.
# Useful when one struct intentionally has a lower bar (e.g. FFI ABI-fixed layout).
#
# [override."HotPathStruct"]
# min_severity = "high"   # only report High findings for this struct
# fail_below   = 50       # allow a lower score for this struct
"#;

pub fn run() -> anyhow::Result<()> {
    let path = Path::new(".padlock.toml");
    if path.exists() {
        anyhow::bail!(
            ".padlock.toml already exists in the current directory. \
             Remove it first or edit it directly."
        );
    }
    std::fs::write(path, TEMPLATE)?;
    println!("Created .padlock.toml — edit it to configure padlock for this project.");
    Ok(())
}
