use crate::impl_nutype_error_conversion;
use nutype::nutype;

/// Código do quarto (máximo 100 caracteres)
#[nutype(
    sanitize(trim),
    validate(not_empty, len_char_max = 100),
    derive(Debug, Clone, PartialEq, Eq, Display, AsRef, Deref, Serialize, Deserialize)
)]
pub struct RoomCode(String);

impl RoomCode {
    pub fn as_str(&self) -> &str {
        self.as_ref()
    }
}

impl_nutype_error_conversion!(RoomCodeError);

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

    #[test]
    fn test_room_code_valid() {
        let code = RoomCode::try_new("STD-001").unwrap();
        assert_eq!(code.as_str(), "STD-001");
    }

    #[test]
    fn test_room_code_empty() {
        let result = RoomCode::try_new("");
        assert!(result.is_err());
    }

    #[test]
    fn test_room_code_too_long() {
        let long = "a".repeat(101);
        let result = RoomCode::try_new(long);
        assert!(result.is_err());
    }
}
