use serde::{Deserialize, Serialize};

/// Dados de pagamento com voucher/desconto
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct VoucherPayment {
    /// Valor do voucher (recomendado)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub amount: Option<f64>,

    /// Descrição do voucher (recomendado)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
}

impl VoucherPayment {
    pub fn new() -> Self {
        Self {
            amount: None,
            description: None,
        }
    }

    pub fn with_amount(mut self, amount: f64) -> Self {
        self.amount = Some(amount);
        self
    }

    pub fn with_description(mut self, description: impl Into<String>) -> Self {
        self.description = Some(description.into());
        self
    }
}

impl Default for VoucherPayment {
    fn default() -> Self {
        Self::new()
    }
}

#[cfg(test)]
mod tests {
    use crate::voucher::VoucherPayment;

    #[test]
    fn test_voucher_payment_builder() {
        let payment = VoucherPayment::new()
            .with_amount(10.0)
            .with_description("Desconto de 10%");

        assert_eq!(payment.amount, Some(10.0));
        assert_eq!(payment.description, Some("Desconto de 10%".to_string()));
    }
}
