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

import dev.lions.unionflow.server.entity.BaseEntity;
import dev.lions.unionflow.server.entity.Membre;

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

import java.math.BigDecimal;
import java.time.LocalDate;

@Entity
@Table(name = "tours_tontine", indexes = {
        @Index(name = "idx_tour_tontine", columnList = "tontine_id")
})
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
@ToString(exclude = { "tontine", "membreBeneficiaire" })
public class TourTontine extends BaseEntity {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tontine_id", nullable = false)
    private Tontine tontine;

    @NotNull
    @Column(name = "ordre_tour", nullable = false)
    private Integer ordreTour;

    @NotNull
    @Column(name = "date_ouverture_cotisations", nullable = false)
    private LocalDate dateOuvertureCotisations;

    @Column(name = "date_tirage_remise")
    private LocalDate dateTirageOuRemise;

    @NotNull
    @Column(name = "montant_cible", nullable = false, precision = 19, scale = 4)
    @Builder.Default
    private BigDecimal montantCible = BigDecimal.ZERO;

    @NotNull
    @Column(name = "cagnotte_collectee", nullable = false, precision = 19, scale = 4)
    @Builder.Default
    private BigDecimal cagnotteCollectee = BigDecimal.ZERO;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "membre_beneficiaire_id")
    private Membre membreBeneficiaire;

    @Column(name = "statut_interne", length = 30)
    private String statutInterne;
}
