package br.gov.sigefp.rh.domain;

import br.gov.sigefp.common.domain.AuditableEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.*;
import lombok.*;

import java.util.UUID;

/**
 * Entidade que representa uma conta bancária de um agente.
 */
@Entity
@Table(name = "agent_bank_account", indexes = {
        @Index(name = "idx_bank_account_agent", columnList = "agent_id"),
        @Index(name = "idx_bank_account_primary", columnList = "agent_id,is_primary")
})
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@lombok.experimental.SuperBuilder
public class AgentBankAccount extends AuditableEntity {

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "agent_id", nullable = false)
    private Agent agent;

    @JsonProperty("agentId")
    public UUID getAgentIdForSerialization() {
        return agent != null ? agent.getId() : null;
    }

    @Column(nullable = false, length = 100)
    private String bank; // Nome do banco

    @Column(nullable = false, length = 20, name = "branch_code")
    private String branchCode; // Código da agência

    @Column(nullable = false, length = 50, name = "account_number")
    private String accountNumber; // Número da conta

    @Column(length = 50)
    private String iban; // IBAN da conta

    @Column(nullable = false, name = "is_primary")
    @Builder.Default
    private Boolean isPrimary = false; // Conta principal para pagamentos
}
