package com.ffii.fpsms.modules.deliveryOrder.entity

import com.fasterxml.jackson.annotation.JsonBackReference
import com.ffii.core.entity.BaseEntity
import com.ffii.fpsms.m18.entity.M18DataLog
import com.ffii.fpsms.modules.deliveryOrder.enums.DeliveryOrderLineStatus
import com.ffii.fpsms.modules.deliveryOrder.enums.DeliveryOrderLineStatusConverter
import com.ffii.fpsms.modules.deliveryOrder.enums.DeliveryOrderStatusConverter
import com.ffii.fpsms.modules.master.entity.Items
import com.ffii.fpsms.modules.master.entity.UomConversion
import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderLine
import jakarta.persistence.*
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import java.math.BigDecimal

@Entity
@Table(name = "delivery_order_line")
open class DeliveryOrderLine: BaseEntity<Long>() {

    @NotNull
    @ManyToOne
    @JoinColumn(name = "itemId", nullable = false)
    open var item: Items? = null

    @Size(max = 100)
    @NotNull
    @Column(name = "itemNo", nullable = false, length = 100)
    open var itemNo: String? = null

    @Column(name = "qty", precision = 14, scale = 2)
    open var qty: BigDecimal? = null

    @Column(name = "qtyM18", precision = 14, scale = 2)
    open var qtyM18: BigDecimal? = null

    @Column(name = "up", precision = 14, scale = 2)
    open var up: BigDecimal? = null

    @ManyToOne
    @JoinColumn(name = "uomId")
    open var uom: UomConversion? = null

    @ManyToOne
    @JoinColumn(name = "uomIdM18")
    open var uomM18: UomConversion? = null

    @Column(name = "price", precision = 14, scale = 2)
    open var price: BigDecimal? = null

    @NotNull
    @Column(name = "status", nullable = false, length = 30)
    @Convert(converter = DeliveryOrderLineStatusConverter::class)
    open var status: DeliveryOrderLineStatus? = null

    @NotNull
    @ManyToOne
    @JoinColumn(name = "m18DataLogId", nullable = false)
    open var m18DataLog: M18DataLog? = null

    @JsonBackReference
    @ManyToOne
    @JoinColumn(name = "deliveryOrderId")
    open var deliveryOrder: DeliveryOrder? = null

    @Column(name = "m18Discount", precision = 14, scale = 2)
    open var m18Discount: BigDecimal? = null

    @Size(max = 20)
    @Column(name = "m18Lot", length = 20)
    open var m18Lot: String? = null
}