/*
 * File: src/main/java/reports/model/purchase/GRN.java
 * Description: This model represents the Goods Received Note (GRN) entity, capturing details
 * related to the receipt of goods in the purchasing process. It includes relationships with
 * Purchase and Supplier entities and a list of GRN items. The GRN model stores metadata like
 * invoice number, dates, and tenant information, and tracks the creation, update, and deletion timestamps.
 */

package com.nebula.erp.reports.model.purchase;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import jakarta.persistence.*;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.List;

@Data
@Entity
@Table(name = "grn")
@Getter
@Setter
public class GRN {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne
    @JoinColumn(name = "purchase_order_id", nullable = false)
    @JsonIgnore
    private Purchase purchase_order;

    @ManyToOne
    @JoinColumn(name = "supplier_id", nullable = false)
    @JsonIgnore
    private Supplier supplier;

    @Column(nullable = false)
    private LocalDateTime date;

    @Column(nullable = false)
    private String invoice_number;

    @Column(nullable = false)
    private String created_by;

    @Column(nullable = false)
    private String tenant;

    @OneToMany(mappedBy = "grn_item", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JsonManagedReference
    private List<GRNItem> grn_items;

    private LocalDateTime created_at = LocalDateTime.now();
    private LocalDateTime updated_at = LocalDateTime.now();
    private LocalDateTime deleted_at = null;

    public Purchase getPurchase() {
        return purchase_order;
    }

    public Supplier getSupplier() {
        return supplier;
    }
}