package br.gov.sigefp.treasury.domain;

import jakarta.persistence.*;
import lombok.*;

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

/**
 * Entidade que representa um item de conciliação bancária.
 * Parte de BankReconciliation.
 */
@Entity
@Table(name = "reconciliation_item", indexes = {
    @Index(name = "idx_reconciliation_item_reconciliation", columnList = "reconciliation_id"),
    @Index(name = "idx_reconciliation_item_status", columnList = "match_status"),
    @Index(name = "idx_reconciliation_item_date", columnList = "transaction_date")
})
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ReconciliationItem {

    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    private UUID id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reconciliation_id", nullable = false)
    private BankReconciliation reconciliation;

    @Column(name = "transaction_date", nullable = false)
    private LocalDate transactionDate;

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

    @Column(name = "statement_amount", precision = 19, scale = 2)
    private BigDecimal statementAmount; // Valor do extrato bancário

    @Column(name = "system_amount", precision = 19, scale = 2)
    private BigDecimal systemAmount; // Valor do sistema

    @Column(name = "match_status", nullable = false, length = 20)
    @Builder.Default
    private String matchStatus = "PENDING"; // MATCHED, UNMATCHED, PENDING

    @Column(name = "matched_transaction_id")
    private UUID matchedTransactionId; // ID da transação do sistema que corresponde
}
