package dev.lions.unionflow.server.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * Entité Ticket pour la gestion des tickets support
 * 
 * @author UnionFlow Team
 * @version 1.0
 */
@Entity
@Table(
    name = "tickets",
    indexes = {
        @Index(name = "idx_ticket_utilisateur", columnList = "utilisateur_id"),
        @Index(name = "idx_ticket_statut", columnList = "statut"),
        @Index(name = "idx_ticket_categorie", columnList = "categorie"),
        @Index(name = "idx_ticket_numero", columnList = "numero_ticket", unique = true)
    }
)
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
public class Ticket extends BaseEntity {

    @NotBlank
    @Column(name = "numero_ticket", nullable = false, unique = true, length = 50)
    private String numeroTicket;

    @NotNull
    @Column(name = "utilisateur_id", nullable = false)
    private UUID utilisateurId;

    @NotBlank
    @Column(name = "sujet", nullable = false, length = 255)
    private String sujet;

    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    @Column(name = "categorie", length = 50)
    private String categorie; // TECHNIQUE, FONCTIONNALITE, UTILISATION, COMPTE, AUTRE

    @Column(name = "priorite", length = 50)
    private String priorite; // BASSE, NORMALE, HAUTE, URGENTE

    @Column(name = "statut", length = 50)
    @Builder.Default
    private String statut = "OUVERT"; // OUVERT, EN_COURS, EN_ATTENTE, RESOLU, FERME

    @Column(name = "agent_id")
    private UUID agentId;

    @Column(name = "agent_nom", length = 255)
    private String agentNom;

    @Column(name = "date_derniere_reponse")
    private LocalDateTime dateDerniereReponse;

    @Column(name = "date_resolution")
    private LocalDateTime dateResolution;

    @Column(name = "date_fermeture")
    private LocalDateTime dateFermeture;

    @Column(name = "nb_messages")
    @Builder.Default
    private Integer nbMessages = 0;

    @Column(name = "nb_fichiers")
    @Builder.Default
    private Integer nbFichiers = 0;

    @Column(name = "note_satisfaction")
    private Integer noteSatisfaction;

    @Column(name = "resolution", columnDefinition = "TEXT")
    private String resolution;
}

