package com.pressing.domain.payment;

import com.pressing.common.entity.SiteScopedEntity;
import com.pressing.domain.customer.Customer;
import com.pressing.domain.invoice.Invoice;
import com.pressing.domain.ironing.IroningInvoice;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "payments")
public class Payment extends SiteScopedEntity {

    @Column(nullable = false, unique = true, length = 40)
    private String receiptNumber;

    // Un règlement porte soit sur une facture de lavage (invoice), soit sur un
    // reçu de repassage (ironingInvoice) — jamais les deux (recouvrement unifié).
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "invoice_id")
    private Invoice invoice;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ironing_invoice_id")
    private IroningInvoice ironingInvoice;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "customer_id")
    private Customer customer;

    @Column(nullable = false)
    private LocalDateTime paymentDateTime;

    @Column(nullable = false, precision = 12, scale = 2)
    private BigDecimal amount;

    @Column(nullable = false, length = 40)
    private String method = "CASH";

    // Référence de transaction (n° Mobile Money, chèque, reçu manuel...)
    @Column(length = 120)
    private String reference;

    @Column(nullable = false, length = 80)
    private String operatorName;

    @Column(length = 255)
    private String notes;
}
