package br.gov.sigefp.treasury.domain;

import br.gov.sigefp.common.domain.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Entidade que representa um lote de pagamentos.
 * Usa IDs para referências a outros módulos.
 */
@Entity
@Table(name = "payment_batch", indexes = {
        @Index(name = "idx_payment_batch_period", columnList = "period_id"),
        @Index(name = "idx_payment_batch_ministry", columnList = "ministry_id"),
        @Index(name = "idx_payment_batch_status", columnList = "status"),
        @Index(name = "idx_payment_batch_created", columnList = "created_at")
})
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class PaymentBatch extends BaseEntity {

    @Column(name = "period_id")
    private Long periodId; // Referência ao período de folha (rh.payroll_period)

    @Column(name = "ministry_id")
    private UUID ministryId; // Referência ao ministério (org.ministry)

    @Column(name = "created_by")
    private UUID createdBy; // ID do usuário que criou o lote

    @Column(nullable = false, length = 20)
    @Builder.Default
    private String status = "CREATED"; // CREATED, PROCESSING, SENT_TO_BANK, COMPLETED, REJECTED - preparado para enum

    @Column(length = 255)
    private String reference;

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

    @OneToMany(mappedBy = "paymentBatch", cascade = CascadeType.ALL, orphanRemoval = true)
    @Builder.Default
    private List<PaymentOrder> paymentOrders = new ArrayList<>();
}
