package com.ffii.fpsms.modules.pickOrder.entity

import com.fasterxml.jackson.annotation.JsonBackReference
import com.fasterxml.jackson.annotation.JsonManagedReference
import com.ffii.core.entity.BaseEntity
import com.ffii.fpsms.modules.master.entity.Items
import com.ffii.fpsms.modules.master.entity.UomConversion
import com.ffii.fpsms.modules.pickOrder.enums.PickOrderLineStatus
import com.ffii.fpsms.modules.pickOrder.enums.PickOrderLineStatusConverter
import com.ffii.fpsms.modules.stock.entity.StockOutLine
import com.ffii.fpsms.modules.stock.entity.SuggestedPickLot
import jakarta.persistence.*
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import java.math.BigDecimal

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

    @JsonBackReference
    @NotNull
    @ManyToOne
    @JoinColumn(name = "poId", nullable = false)
    open var pickOrder: PickOrder? = null

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

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

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

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

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

    @JsonManagedReference
    @OneToMany(mappedBy = "pickOrderLine", cascade = [CascadeType.ALL], orphanRemoval = true)
    open var suggestedPickLots: MutableList<SuggestedPickLot> = mutableListOf()
}