package com.coder.purchase.order.model;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

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

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "purchase_order_info")
public class PurchaseOrder {

    /* ========= PRIMARY KEY ========= */
    @Id
    private String purchaseOrderId;   // PO-2026-001

    /* ========= BASIC DETAILS ========= */
    private String purchaseOrderNumber;
    private String purchaseOrderDate;
    private String expectedDeliveryDate;

    private String vendorId;
    private String vendorName;
    private String vendorContact;
    private String vendorGSTNo;
    private String shippingAddress;

    /* ========= ASSET DETAILS ========= */
    private String assetType;
    private String assetMake;
    private String assetModel;

    /* ========= QUANTITY & PRICING ========= */
    private Integer quantity;

    @Column(precision = 12, scale = 2)
    private BigDecimal unitPrice;

    @Column(precision = 5, scale = 2)
    private BigDecimal discount; // %

    @Column(precision = 5, scale = 2)
    private BigDecimal gst;

    /* ========= CALCULATED FIELDS ========= */
    @Column(precision = 12, scale = 2)
    private BigDecimal subTotal;

    @Column(precision = 12, scale = 2)
    private BigDecimal totalTax;
    
    @Column(precision = 12, scale = 2)
    private BigDecimal totalDiscount;

    @Column(precision = 12, scale = 2)
    private BigDecimal grandTotal;
    
    @Column(precision = 12, scale = 2)
    private BigDecimal advancePaid;

    @Column(precision = 12, scale = 2)
    private BigDecimal balanceAmount;
    
    /* ========= PAYMENT ========= */
    private String paymentStatus;   // Pending / Paid / Partial
    
    private String paymentMode;     // UPI / Bank / Cash
    
    private String transactionReference;
    
    private LocalDate paymentDueDate;
    
    /* ========= APPROVAL ========= */
    private String approvedBy;
    
    private LocalDate approvedDate;
    
    private String remarks;
    
    private String poStatus;

    /* ========= AUDIT ========= */
    private String createdBy;

    private LocalDateTime createdDate;
    
    private LocalDateTime updatedDate;

    private String status;


    @PrePersist
    public void prePersist() {
        this.createdDate = LocalDateTime.now();
        this.updatedDate = LocalDateTime.now();
        this.status = "Active";
    }

    @PreUpdate
    public void preUpdate() {
        this.updatedDate = LocalDateTime.now();
    }

	
}