package dev.lions.unionflow.server.entity.mutuelle.credit;

import dev.lions.unionflow.server.api.enums.mutuelle.credit.StatutEcheanceCredit;
import dev.lions.unionflow.server.entity.BaseEntity;

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

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

@Entity
@Table(name = "echeances_credit", indexes = {
        @Index(name = "idx_echeance_demande", columnList = "demande_credit_id")
})
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
@ToString(exclude = "demandeCredit")
public class EcheanceCredit extends BaseEntity {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "demande_credit_id", nullable = false)
    private DemandeCredit demandeCredit;

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

    @NotNull
    @Column(name = "date_echeance_prevue", nullable = false)
    private LocalDate dateEcheancePrevue;

    @Column(name = "date_paiement_effectif")
    private LocalDate datePaiementEffectif;

    @NotNull
    @Column(name = "capital_amorti", nullable = false, precision = 19, scale = 4)
    private BigDecimal capitalAmorti;

    @NotNull
    @Column(name = "interets_periode", nullable = false, precision = 19, scale = 4)
    private BigDecimal interetsDeLaPeriode;

    @NotNull
    @Column(name = "montant_total_exigible", nullable = false, precision = 19, scale = 4)
    private BigDecimal montantTotalExigible;

    @NotNull
    @Column(name = "capital_restant_du", nullable = false, precision = 19, scale = 4)
    private BigDecimal capitalRestantDu;

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

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

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