package dev.lions.unionflow.server.entity.collectefonds;

import dev.lions.unionflow.server.api.enums.collectefonds.StatutCampagneCollecte;
import dev.lions.unionflow.server.entity.BaseEntity;
import dev.lions.unionflow.server.entity.Organisation;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Entity
@Table(name = "campagnes_collecte", indexes = {
        @Index(name = "idx_collecte_organisation", columnList = "organisation_id")
})
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
public class CampagneCollecte extends BaseEntity {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "organisation_id", nullable = false)
    private Organisation organisation;

    @NotBlank
    @Column(name = "titre", nullable = false, length = 200)
    private String titre;

    @Column(name = "courte_description", length = 500)
    private String courteDescription;

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

    @Column(name = "image_banniere_url", length = 500)
    private String imageBanniereUrl;

    @Column(name = "objectif_financier", precision = 19, scale = 4)
    private BigDecimal objectifFinancier;

    @Column(name = "montant_collecte_actuel", precision = 19, scale = 4)
    @Builder.Default
    private BigDecimal montantCollecteActuel = BigDecimal.ZERO;

    @Column(name = "nombre_donateurs")
    @Builder.Default
    private Integer nombreDonateurs = 0;

    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "statut", nullable = false, length = 50)
    @Builder.Default
    private StatutCampagneCollecte statut = StatutCampagneCollecte.BROUILLON;

    @NotNull
    @Column(name = "date_ouverture", nullable = false)
    @Builder.Default
    private LocalDateTime dateOuverture = LocalDateTime.now();

    @Column(name = "date_cloture_prevue")
    private LocalDateTime dateCloturePrevue;

    @Column(name = "est_publique", nullable = false)
    @Builder.Default
    private Boolean estPublique = true;
}
