use dirigent_fermata::core::toml_config::{BotignoreToml, OpRules, BashRules};

#[test]
fn parses_full_config() {
    let src = r#"
[read]
patterns = [".env*", "secrets/**"]

[write]
patterns = ["vendor/**", "*.lock"]

[bash]
deny = ["rm -rf /", "git push --force*"]
ask = ["rm:*"]
allow_prefixes = ["make test", "git checkout:*"]
"#;
    let cfg: BotignoreToml = toml::from_str(src).unwrap();
    assert_eq!(cfg.read.unwrap().patterns, vec![".env*", "secrets/**"]);
    assert_eq!(cfg.write.unwrap().patterns, vec!["vendor/**", "*.lock"]);
    let bash = cfg.bash.unwrap();
    assert_eq!(bash.deny, vec!["rm -rf /", "git push --force*"]);
    assert_eq!(bash.ask, vec!["rm:*"]);
    assert_eq!(bash.allow_prefixes, vec!["make test", "git checkout:*"]);
}

#[test]
fn empty_config_is_valid() {
    let cfg: BotignoreToml = toml::from_str("").unwrap();
    assert!(cfg.read.is_none());
    assert!(cfg.write.is_none());
    assert!(cfg.bash.is_none());
}

#[test]
fn loads_from_disk_when_present() {
    let tmp = tempfile::tempdir().unwrap();
    std::fs::write(tmp.path().join("botignore.toml"), "[read]\npatterns = [\".env\"]\n").unwrap();
    let cfg = BotignoreToml::load(tmp.path()).unwrap();
    assert_eq!(cfg.read.unwrap().patterns, vec![".env"]);
}

#[test]
fn loads_empty_when_missing() {
    let tmp = tempfile::tempdir().unwrap();
    let cfg = BotignoreToml::load(tmp.path()).unwrap();
    assert!(cfg.read.is_none());
}
