package dev.lions.unionflow.client.dto;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

/**
 * DTO côté client pour les logs d'audit
 * Correspond au AuditLogDTO du backend avec méthodes utilitaires pour l'affichage
 *
 * @author UnionFlow Team
 * @version 1.0
 */
public class AuditLogDTO implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    private UUID id;
    private String typeAction;
    private String severite;
    private String utilisateur;
    private String role;
    private String module;
    private String description;
    private String details;
    private String ipAddress;
    private String userAgent;
    private String sessionId;
    private LocalDateTime dateHeure;
    private String donneesAvant;
    private String donneesApres;
    private String entiteId;
    private String entiteType;
    
    // Getters et Setters
    public UUID getId() { return id; }
    public void setId(UUID id) { this.id = id; }
    
    public String getTypeAction() { return typeAction; }
    public void setTypeAction(String typeAction) { this.typeAction = typeAction; }
    
    public String getSeverite() { return severite; }
    public void setSeverite(String severite) { this.severite = severite; }
    
    public String getUtilisateur() { return utilisateur; }
    public void setUtilisateur(String utilisateur) { this.utilisateur = utilisateur; }
    
    public String getRole() { return role; }
    public void setRole(String role) { this.role = role; }
    
    public String getModule() { return module; }
    public void setModule(String module) { this.module = module; }
    
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    
    public String getDetails() { return details; }
    public void setDetails(String details) { this.details = details; }
    
    public String getIpAddress() { return ipAddress; }
    public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; }
    
    public String getUserAgent() { return userAgent; }
    public void setUserAgent(String userAgent) { this.userAgent = userAgent; }
    
    public String getSessionId() { return sessionId; }
    public void setSessionId(String sessionId) { this.sessionId = sessionId; }
    
    public LocalDateTime getDateHeure() { return dateHeure; }
    public void setDateHeure(LocalDateTime dateHeure) { this.dateHeure = dateHeure; }
    
    public String getDonneesAvant() { return donneesAvant; }
    public void setDonneesAvant(String donneesAvant) { this.donneesAvant = donneesAvant; }
    
    public String getDonneesApres() { return donneesApres; }
    public void setDonneesApres(String donneesApres) { this.donneesApres = donneesApres; }
    
    public String getEntiteId() { return entiteId; }
    public void setEntiteId(String entiteId) { this.entiteId = entiteId; }
    
    public String getEntiteType() { return entiteType; }
    public void setEntiteType(String entiteType) { this.entiteType = entiteType; }
    
    // Méthodes utilitaires pour l'affichage
    
    public String getDateFormatee() {
        if (dateHeure == null) return "";
        return dateHeure.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
    }
    
    public String getHeureFormatee() {
        if (dateHeure == null) return "";
        return dateHeure.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
    }
    
    public String getDateHeureComplete() {
        if (dateHeure == null) return "";
        return dateHeure.format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"));
    }
    
    public String getSeveriteLibelle() {
        if (severite == null) return "";
        return switch (severite) {
            case "SUCCESS" -> "Succès";
            case "INFO" -> "Info";
            case "WARNING" -> "Attention";
            case "ERROR" -> "Erreur";
            case "CRITICAL" -> "Critique";
            default -> severite;
        };
    }
    
    public String getSeveriteSeverity() {
        if (severite == null) return "secondary";
        return switch (severite) {
            case "SUCCESS" -> "success";
            case "INFO" -> "info";
            case "WARNING" -> "warning";
            case "ERROR", "CRITICAL" -> "danger";
            default -> "secondary";
        };
    }
    
    public String getSeveriteIcon() {
        if (severite == null) return "pi pi-circle";
        return switch (severite) {
            case "SUCCESS" -> "pi pi-check";
            case "INFO" -> "pi pi-info";
            case "WARNING" -> "pi pi-exclamation-triangle";
            case "ERROR" -> "pi pi-times";
            case "CRITICAL" -> "pi pi-ban";
            default -> "pi pi-circle";
        };
    }
    
    public String getActionIcon() {
        if (typeAction == null) return "pi pi-circle";
        return switch (typeAction) {
            case "CONNEXION" -> "pi pi-sign-in";
            case "DECONNEXION" -> "pi pi-sign-out";
            case "CREATION" -> "pi pi-plus";
            case "MODIFICATION" -> "pi pi-pencil";
            case "SUPPRESSION" -> "pi pi-trash";
            case "CONSULTATION" -> "pi pi-eye";
            case "EXPORT" -> "pi pi-download";
            case "CONFIGURATION" -> "pi pi-cog";
            default -> "pi pi-circle";
        };
    }
    
    public String getActionLibelle() {
        if (typeAction == null) return "";
        return switch (typeAction) {
            case "CONNEXION" -> "Connexion";
            case "DECONNEXION" -> "Déconnexion";
            case "CREATION" -> "Création";
            case "MODIFICATION" -> "Modification";
            case "SUPPRESSION" -> "Suppression";
            case "CONSULTATION" -> "Consultation";
            case "EXPORT" -> "Export";
            case "CONFIGURATION" -> "Configuration";
            default -> typeAction;
        };
    }
    
    public String getModuleLibelle() {
        if (module == null) return "";
        return switch (module) {
            case "AUTH" -> "Authentification";
            case "MEMBRES" -> "Membres";
            case "COTISATIONS" -> "Cotisations";
            case "EVENTS" -> "Événements";
            case "DOCUMENTS" -> "Documents";
            case "CONFIG" -> "Configuration";
            case "RAPPORTS" -> "Rapports";
            default -> module;
        };
    }
    
    public String getUserAgentCourt() {
        if (userAgent == null || userAgent.isEmpty()) return "";
        return userAgent.length() > 50 ? userAgent.substring(0, 50) + "..." : userAgent;
    }
}
