//! Test Parseable macro supports required bool fields.
use mad_hatter::Parseable;
use mad_hatter::llm::Parseable as _;

#[derive(Parseable, Debug, PartialEq)]
enum BoolAction {
    /// @render 无限等待
    InfiniteIdle {
        /// @render 理由
        reason: String,
        /// @render 确认
        confirm: bool,
    },
}

#[test]
fn test_bool_required_true() {
    let input = "BoolAction-b1\ninfinite_idle\nreason-b1\npending user reply\nconfirm-b1\ntrue";
    let result = BoolAction::from_markdown(input, "b1").unwrap();
    assert_eq!(result.len(), 1);
    assert_eq!(result[0], BoolAction::InfiniteIdle { reason: "pending user reply".to_string(), confirm: true });
}

#[test]
fn test_bool_required_false() {
    let input = "BoolAction-b2\ninfinite_idle\nreason-b2\nwaiting\nconfirm-b2\nfalse";
    let result = BoolAction::from_markdown(input, "b2").unwrap();
    assert_eq!(result[0], BoolAction::InfiniteIdle { reason: "waiting".to_string(), confirm: false });
}

#[test]
fn test_bool_required_empty() {
    let input = "BoolAction-b3\ninfinite_idle\nreason-b3\nwaiting\nconfirm-b3\n";
    let result = BoolAction::from_markdown(input, "b3");
    assert!(result.is_err(), "empty bool should error");
    let err = result.unwrap_err();
    assert!(err.contains("confirm") && err.contains("empty"), "Error: {}", err);
}

#[test]
fn test_bool_required_invalid() {
    let input = "BoolAction-b4\ninfinite_idle\nreason-b4\nwaiting\nconfirm-b4\nyes";
    let result = BoolAction::from_markdown(input, "b4");
    assert!(result.is_err(), "'yes' is not a valid bool");
    let err = result.unwrap_err();
    assert!(err.contains("confirm") && (err.contains("parse") || err.contains("Failed")), "Error: {}", err);
}
