use service_kit::api_dto;

#[api_dto]
pub enum TaskAcknowledgement {
    Accepted,
    Rejected { reason: String },
}

#[cfg(test)]
mod tests {
    use super::*;
    use serde_json::json;

    #[test]
    fn test_ack_serialization() {
        // 1. Test Accepted
        let ack = TaskAcknowledgement::Accepted;
        let json = serde_json::to_value(&ack).unwrap();
        assert_eq!(json, json!("Accepted"));

        // 2. Test Rejected
        let ack = TaskAcknowledgement::Rejected { reason: "Bad Key".to_string() };
        let json = serde_json::to_value(&ack).unwrap();
        assert_eq!(json, json!({
            "Rejected": {
                "reason": "Bad Key"
            }
        }));
    }

    #[test]
    fn test_ack_deserialization() {
        // 1. Test Accepted
        let json = json!("Accepted");
        let ack: TaskAcknowledgement = serde_json::from_value(json).unwrap();
        match ack {
            TaskAcknowledgement::Accepted => (),
            _ => panic!("Expected Accepted"),
        }

        // 2. Test Rejected
        let json = json!({
            "Rejected": {
                "reason": "Timeout"
            }
        });
        let ack: TaskAcknowledgement = serde_json::from_value(json).unwrap();
        match ack {
            TaskAcknowledgement::Rejected { reason } => assert_eq!(reason, "Timeout"),
            _ => panic!("Expected Rejected"),
        }
    }
}
