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

import com.fasterxml.jackson.annotation.JsonManagedReference
import com.ffii.core.entity.BaseEntity
import com.ffii.fpsms.modules.stock.entity.Inventory
import jakarta.persistence.*
import jakarta.validation.constraints.NotNull
import java.time.LocalDateTime

@Entity
@Table(name = "items")
open class Items : BaseEntity<Long>() {
    @NotNull
    @Column(name = "code")
    open var code: String? = null

    @NotNull
    @Column(name = "name")
    open var name: String? = null

    @Column(name = "description")
    open var description: String? = null

    @Column(name = "remarks")
    open var remarks: String? = null

    @NotNull
    @Column(name = "type")
    open var type: String? = null

    @Column(name = "shelfLife")
    open var shelfLife: Double? = null

    @Column(name = "countryOfOrigin")
    open var countryOfOrigin: String? = null

    @Column(name = "store_id", nullable = true, length = 255)
    open var store_id: String? = null

    @Column(name = "warehouse", nullable = true, length = 255)
    open var warehouse: String? = null

    @Column(name = "area", nullable = true, length = 255)
    open var area: String? = null

    @Column(name = "slot", nullable = true, length = 255)
    open var slot: String? = null

    @Column(name = "LocationCode", nullable = true, length = 255)
    open var LocationCode: String? = null

    @Column(name = "isEgg", nullable = true)
    open var isEgg: Boolean? = false

    @Column(name = "isFee", nullable = true)
    open var isFee: Boolean? = false

    @Column(name = "isBag", nullable = true)
    open var isBag: Boolean? = false

    @Column(name = "maxQty")
    open var maxQty: Double? = null

    @Column(name = "m18Id")
    open var m18Id: Long? = null

    @Column(name = "m18LastModifyDate")
    open var m18LastModifyDate: LocalDateTime? = null

    @Column(name = "AverageUnitPrice", nullable = true, length = 255)
    open var averageUnitPrice: String? = null

    @Column(name = "LatestMarketUnitPrice", nullable = true)
    open var latestMarketUnitPrice: Double? = null

    @Column(name = "latestMupUpdatedDate", nullable = true)
    open var latestMupUpdatedDate: LocalDateTime? = null
    @Column(name = "item_Order", nullable = true)
    open var item_Order: Int? = null
    @JsonManagedReference
    @OneToMany(mappedBy = "item", cascade = [CascadeType.ALL], orphanRemoval = true)
    open var itemUoms: MutableList<ItemUom> = mutableListOf()

    @JsonManagedReference
    @OneToMany(mappedBy = "item", cascade = [CascadeType.ALL], orphanRemoval = true)
    open var inventories: MutableList<Inventory> = mutableListOf()

    @JsonManagedReference
    @OneToMany(mappedBy = "item", cascade = [CascadeType.ALL], orphanRemoval = true)
    open var boms: MutableList<Bom> = mutableListOf()

    @ManyToOne
    @JoinColumn(name = "categoryId")
    open var category: ItemCategory? = null

    @ManyToOne
    @JsonManagedReference
    @JoinColumn(name = "qcCategoryId")
    open var qcCategory: QcCategory? = null

}