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

/// Regime de alimentação do hotel (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 BoardBasis(String);

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

impl_nutype_error_conversion!(BoardBasisError);

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

    #[test]
    fn test_board_basis_valid() {
        let board = BoardBasis::try_new("all-inclusive").unwrap();
        assert_eq!(board.as_str(), "all-inclusive");
    }

    #[test]
    fn test_board_basis_variants() {
        let types = vec!["breakfast", "half-board", "full-board", "all-inclusive"];
        for t in types {
            let board = BoardBasis::try_new(t).unwrap();
            assert_eq!(board.as_str(), t);
        }
    }

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

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