package com.nebula.erp.sales.model;

import jakarta.persistence.*;
import lombok.Data;
import java.time.Instant;

@Data
@Entity
@Table(name = "payment_history")
public class PaymentHistory {

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

    @Column(nullable = false)
    private String patient_id;

    @Column(nullable = false)
    private String mrn_no;

    @Column(nullable = true)
    private Long sales_id;

    @Column(nullable = true)
    private String encounter_id;

    private String custom_encounter_id;

    @Column(nullable = false)
    private Double credit = 0.0;

    @Column(nullable = true)
    private Double advance = 0.0;

    @Column(nullable = false)
    private Double debit = 0.0;

    @Column(nullable = true)
    private Double advance_used = 0.0;

    @Column(nullable = true)
    private String entry_type = "NORMAL";

    @Column(nullable = false)
    private String tenant;

    @Column(nullable = false)
    private String created_by;

    private String payment_method;

    // Razorpay sub-method: UPI, CREDIT_CARD, DEBIT_CARD (used for accounting)
    private String payment_sub_method;

    @Column(nullable = false, updatable = false)
    private Instant created_at;

    @Column(nullable = false)
    private Instant updated_at;

    public String getPayment_method() {
        return payment_method;
    }

    public void setPayment_method(String payment_method) {
        this.payment_method = payment_method;
    }

    @PrePersist
    protected void onCreate() {
        Instant now = Instant.now();
        created_at = now;
        updated_at = now;
    }

    @PreUpdate
    protected void onUpdate() {
        updated_at = Instant.now();
    }
}