package dev.lions.unionflow.client.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.io.Serializable;

public class AssociationDTO implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    private Long id;
    
    @NotBlank(message = "Le nom de l'association est obligatoire")
    private String nom;
    
    private String description;
    private String adresse;
    private String telephone;
    private String email;
    private String siteWeb;
    
    @NotNull(message = "Le type d'association est obligatoire")
    private String typeAssociation;
    
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate dateCreation;
    
    private String numeroRegistre;
    private String statut;
    private Integer nombreMembres;
    private String responsablePrincipal;
    private String telephoneResponsable;
    private String emailResponsable;
    
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime dateDerniereActivite;
    
    private String region;
    private String ville;
    private String quartier;
    
    // Constructeurs
    public AssociationDTO() {}
    
    public AssociationDTO(String nom, String typeAssociation) {
        this.nom = nom;
        this.typeAssociation = typeAssociation;
        this.statut = "ACTIVE";
        this.dateCreation = LocalDate.now();
        this.nombreMembres = 0;
    }
    
    // Getters et Setters
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    
    public String getNom() { return nom; }
    public void setNom(String nom) { this.nom = nom; }
    
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    
    public String getAdresse() { return adresse; }
    public void setAdresse(String adresse) { this.adresse = adresse; }
    
    public String getTelephone() { return telephone; }
    public void setTelephone(String telephone) { this.telephone = telephone; }
    
    public String getEmail() { return email; }
    public void setEmail(String email) { this.email = email; }
    
    public String getSiteWeb() { return siteWeb; }
    public void setSiteWeb(String siteWeb) { this.siteWeb = siteWeb; }
    
    public String getTypeAssociation() { return typeAssociation; }
    public void setTypeAssociation(String typeAssociation) { this.typeAssociation = typeAssociation; }
    
    public LocalDate getDateCreation() { return dateCreation; }
    public void setDateCreation(LocalDate dateCreation) { this.dateCreation = dateCreation; }
    
    public String getNumeroRegistre() { return numeroRegistre; }
    public void setNumeroRegistre(String numeroRegistre) { this.numeroRegistre = numeroRegistre; }
    
    public String getStatut() { return statut; }
    public void setStatut(String statut) { this.statut = statut; }
    
    public Integer getNombreMembres() { return nombreMembres; }
    public void setNombreMembres(Integer nombreMembres) { this.nombreMembres = nombreMembres; }
    
    public String getResponsablePrincipal() { return responsablePrincipal; }
    public void setResponsablePrincipal(String responsablePrincipal) { this.responsablePrincipal = responsablePrincipal; }
    
    public String getTelephoneResponsable() { return telephoneResponsable; }
    public void setTelephoneResponsable(String telephoneResponsable) { this.telephoneResponsable = telephoneResponsable; }
    
    public String getEmailResponsable() { return emailResponsable; }
    public void setEmailResponsable(String emailResponsable) { this.emailResponsable = emailResponsable; }
    
    public LocalDateTime getDateDerniereActivite() { return dateDerniereActivite; }
    public void setDateDerniereActivite(LocalDateTime dateDerniereActivite) { this.dateDerniereActivite = dateDerniereActivite; }
    
    public String getRegion() { return region; }
    public void setRegion(String region) { this.region = region; }
    
    public String getVille() { return ville; }
    public void setVille(String ville) { this.ville = ville; }
    
    public String getQuartier() { return quartier; }
    public void setQuartier(String quartier) { this.quartier = quartier; }
    
    // Propriétés dérivées
    public String getTypeLibelle() {
        return switch (typeAssociation != null ? typeAssociation : "") {
            case "LIONS_CLUB" -> "Club Lions";
            case "ASSOCIATION_LOCALE" -> "Association Locale";
            case "FEDERATION" -> "Fédération";
            case "COOPERATIVE" -> "Coopérative";
            case "MUTUELLE" -> "Mutuelle";
            case "SYNDICAT" -> "Syndicat";
            default -> typeAssociation;
        };
    }
    
    public String getStatutLibelle() {
        return switch (statut != null ? statut : "") {
            case "ACTIVE" -> "Active";
            case "INACTIVE" -> "Inactive";
            case "SUSPENDUE" -> "Suspendue";
            case "DISSOUTE" -> "Dissoute";
            default -> statut;
        };
    }
    
    public String getStatutSeverity() {
        return switch (statut != null ? statut : "") {
            case "ACTIVE" -> "success";
            case "INACTIVE" -> "warning";
            case "SUSPENDUE" -> "danger";
            case "DISSOUTE" -> "secondary";
            default -> "info";
        };
    }
    
    public String getAdresseComplete() {
        StringBuilder addr = new StringBuilder();
        if (adresse != null && !adresse.trim().isEmpty()) {
            addr.append(adresse);
        }
        if (quartier != null && !quartier.trim().isEmpty()) {
            if (addr.length() > 0) addr.append(", ");
            addr.append(quartier);
        }
        if (ville != null && !ville.trim().isEmpty()) {
            if (addr.length() > 0) addr.append(", ");
            addr.append(ville);
        }
        if (region != null && !region.trim().isEmpty()) {
            if (addr.length() > 0) addr.append(", ");
            addr.append(region);
        }
        return addr.toString();
    }
    
    @Override
    public String toString() {
        return "AssociationDTO{" +
                "id=" + id +
                ", nom='" + nom + '\'' +
                ", typeAssociation='" + typeAssociation + '\'' +
                ", statut='" + statut + '\'' +
                ", nombreMembres=" + nombreMembres +
                '}';
    }
}