package br.gov.sigefp.treasury.domain;

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

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * Entidade que representa uma aprovação individual em um workflow hierárquico.
 * Parte do histórico de aprovações de PaymentAuthorization.
 */
@Entity
@Table(name = "approval", indexes = {
    @Index(name = "idx_approval_authorization", columnList = "authorization_id"),
    @Index(name = "idx_approval_approver", columnList = "approved_by"),
    @Index(name = "idx_approval_level", columnList = "level")
})
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Approval {

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

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "authorization_id", nullable = false)
    private PaymentAuthorization authorization;

    @Column(nullable = false)
    private Integer level; // Nível da aprovação (1, 2, 3...)

    @Column(name = "approved_by", nullable = false)
    private UUID approvedBy; // Usuário que aprovou

    @Column(name = "approved_at", nullable = false)
    private LocalDateTime approvedAt;

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

    @Column(name = "signature_hash", length = 255)
    private String signatureHash; // Hash da assinatura digital (futuro)
}
