use super::address::Address;

/// Alias para endereço de cobrança
///
/// `ShippingAddress` é semanticamente um endereço de cobrança, mas usa
/// exatamente a mesma estrutura e funcionalidades de `Address`.
///
/// # Exemplo
///
/// ```rust
/// use konduto::Country;
/// use konduto::ShippingAddress;
///
/// let shipping = ShippingAddress::builder()
///     .name("João Silva").unwrap()
///     .address1("Rua das Flores, 123").unwrap()
///     .city("São Paulo").unwrap()
///     .state("SP").unwrap()
///     .zip("01234-567").unwrap()
///     .country(Country::BR)
///     .build();
/// ```
pub type ShippingAddress = Address;

// Re-exportar os tipos de validação para facilitar o uso
pub use super::address::{
    AddressLine as ShippingLine,
    AddressName as ShippingName,
    City as ShippingCity,
    Country as ShippingCountry,
    CountryCode as ShippingCountryCode, // Alias mantido para compatibilidade
    State as ShippingState,
    ZipCode as ShippingZipCode,
};

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

    #[test]
    fn test_shipping_address_creation() {
        let shipping = ShippingAddress::builder()
            .name("John Doe")
            .unwrap()
            .address1("123 Main St")
            .unwrap()
            .city("São Paulo")
            .unwrap()
            .state("SP")
            .unwrap()
            .zip("01234-567")
            .unwrap()
            .country(Country::BR)
            .build();

        assert!(shipping.name.is_some());
        assert_eq!(shipping.name.unwrap().as_str(), "John Doe");
        assert_eq!(shipping.city.unwrap().as_str(), "São Paulo");
    }

    #[test]
    fn test_shipping_address_serialization() {
        let shipping = ShippingAddress::builder()
            .name("Jane Doe")
            .unwrap()
            .address1("456 Oak Ave")
            .unwrap()
            .city("Rio de Janeiro")
            .unwrap()
            .state("RJ")
            .unwrap()
            .zip("20000-000")
            .unwrap()
            .country(Country::BR)
            .build();

        let json = serde_json::to_string(&shipping).unwrap();
        assert!(json.contains("Jane Doe"));
        assert!(json.contains("Rio de Janeiro"));
    }

    #[test]
    fn test_shipping_address_default() {
        let shipping = ShippingAddress::default();
        assert!(shipping.name.is_none());
        assert!(shipping.address1.is_none());
    }

    #[test]
    fn test_shipping_address_is_address() {
        // Verifica que ShippingAddress pode ser usado onde Address é esperado
        fn accepts_address(_addr: &Address) {}

        let shipping = ShippingAddress::builder().name("Test").unwrap().build();

        accepts_address(&shipping); // Funciona porque ShippingAddress = Address
    }
}
