package com.ffii.fpsms.modules.purchaseOrder.entity

import com.ffii.core.entity.BaseEntity
import com.ffii.fpsms.modules.master.entity.Items
import com.ffii.fpsms.m18.entity.M18DataLog
import com.ffii.fpsms.modules.master.entity.Currency
import com.ffii.fpsms.modules.master.entity.UomConversion
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatus
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatusConverter
import jakarta.persistence.*
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import java.math.BigDecimal

@Entity
@Table(name = "purchase_order_line")
open class PurchaseOrderLine : BaseEntity<Long>() {
    @NotNull
    @ManyToOne
    @JoinColumn(name = "itemId", nullable = false)
    open var item: Items? = null

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

//    @NotNull
//    @ManyToOne(fetch = FetchType.LAZY, optional = false)
//    @JoinColumn(name = "uomId", nullable = false)
//    open var uom: UomConversion? = null

    @NotNull
    @ManyToOne
    @JoinColumn(name = "purchaseOrderId", nullable = false)
    open var purchaseOrder: PurchaseOrder? = null

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

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

    @Convert(converter = PurchaseOrderLineStatusConverter::class)
    @NotNull
    @Column(name = "status", nullable = false, length = 10)
    open var status: PurchaseOrderLineStatus? = null

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

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