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

import dev.lions.unionflow.server.api.enums.mutuelle.parts.TypeTransactionPartsSociales;
import dev.lions.unionflow.server.entity.BaseEntity;
import jakarta.persistence.*;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.*;

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

@Entity
@Table(name = "transactions_parts_sociales", indexes = {
        @Index(name = "idx_tps_compte", columnList = "compte_id"),
        @Index(name = "idx_tps_date", columnList = "date_transaction")
})
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
public class TransactionPartsSociales extends BaseEntity {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "compte_id", nullable = false)
    private ComptePartsSociales compte;

    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "type_transaction", nullable = false, length = 50)
    private TypeTransactionPartsSociales typeTransaction;

    @NotNull
    @Min(1)
    @Column(name = "nombre_parts", nullable = false)
    private Integer nombreParts;

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

    @Column(name = "solde_parts_avant", nullable = false)
    @Builder.Default
    private Integer soldePartsAvant = 0;

    @Column(name = "solde_parts_apres", nullable = false)
    @Builder.Default
    private Integer soldePartsApres = 0;

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

    @Column(name = "reference_externe", length = 100)
    private String referenceExterne;

    @NotNull
    @Column(name = "date_transaction", nullable = false)
    @Builder.Default
    private LocalDateTime dateTransaction = LocalDateTime.now();
}
