package com.social.media.domain.company.valueobject;

/**
 * Value Object representing a company address
 */
public record Address(
    String street,
    String number,
    String complement,
    String neighborhood,
    String city,
    String state,
    String country,
    String zipCode
) {
    
    public Address {
        if (city != null && city.trim().isEmpty()) {
            city = null;
        }
        if (state != null && state.trim().isEmpty()) {
            state = null;
        }
        if (country == null || country.trim().isEmpty()) {
            country = "Brasil"; // Default to Brazil
        }
    }
    
    public static Address create(String street, String number, String city, String state, String zipCode) {
        return new Address(street, number, null, null, city, state, "Brasil", zipCode);
    }
    
    public String getFullAddress() {
        StringBuilder sb = new StringBuilder();
        
        if (street != null && !street.isEmpty()) {
            sb.append(street);
            if (number != null && !number.isEmpty()) {
                sb.append(", ").append(number);
            }
        }
        
        if (complement != null && !complement.isEmpty()) {
            if (sb.length() > 0) sb.append(", ");
            sb.append(complement);
        }
        
        if (neighborhood != null && !neighborhood.isEmpty()) {
            if (sb.length() > 0) sb.append(", ");
            sb.append(neighborhood);
        }
        
        if (city != null && !city.isEmpty()) {
            if (sb.length() > 0) sb.append(", ");
            sb.append(city);
        }
        
        if (state != null && !state.isEmpty()) {
            if (sb.length() > 0) sb.append(", ");
            sb.append(state);
        }
        
        if (country != null && !country.isEmpty()) {
            if (sb.length() > 0) sb.append(", ");
            sb.append(country);
        }
        
        return sb.toString();
    }
    
    @Override
    public String toString() {
        return getFullAddress();
    }
}
