package com.ffii.fpsms.modules.master.entity

import com.fasterxml.jackson.annotation.JsonBackReference
import com.ffii.core.entity.BaseEntity
import jakarta.persistence.*
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import java.math.BigDecimal
import java.time.Instant
import java.time.LocalDateTime

@Table(name = "bom_material")
@Entity
open class BomMaterial : BaseEntity<Long>() {
    @JsonBackReference
    @ManyToOne
    @JoinColumn(name = "itemId")
    open var item: Items? = null

    @Size(max = 100)
    @Column(name = "itemName", length = 100)
    open var itemName: String? = null

    @NotNull
    @Column(name = "isConsumable", nullable = false)
    open var isConsumable: Boolean? = false

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

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

    @Size(max = 100)
    @Column(name = "uomName", length = 100)
    open var uomName: String? = null

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

    @ManyToOne
    @JoinColumn(name = "salesUnitId")
    open var salesUnit: UomConversion? = null

    @Column(name = "salesUnitCode")
    open var salesUnitCode: String? = null
    @Column(name = "baseQty", precision = 14, scale = 2)
    open var baseQty: BigDecimal? = null
    @Column(name = "baseUnit", nullable = false)
    open var baseUnit: Integer? = null
    @Column(name = "baseUnitName", length = 100)
    open var baseUnitName: String? = null
    @Column(name = "stockQty", precision = 14, scale = 2)
    open var stockQty: BigDecimal? = null
    @Column(name = "stockUnit", nullable = false)
    open var stockUnit: Integer? = null
    @Column(name = "stockUnitName", length = 100)
    open var stockUnitName: String? = null
    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "bomId", nullable = false)
    @JsonBackReference
    open var bom: Bom? = null

//    @NotNull
    @Column(name = "m18Id", nullable = false)
    open var m18Id: Long? = null

//    @NotNull
    @Column(name = "m18LastModifyDate", nullable = false)
    open var m18LastModifyDate: LocalDateTime? = null

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