package com.ffii.fpsms.modules.stock.entity

import com.ffii.core.entity.BaseEntity
import com.ffii.fpsms.modules.master.entity.UomConversion
import com.ffii.fpsms.modules.stock.enums.StockTakeLineStatus
import com.ffii.fpsms.modules.stock.enums.StockTakeLineStatusConverter
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.persistence.Convert
import jakarta.persistence.Column
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import java.math.BigDecimal
import java.time.LocalDateTime

@Entity
@Table(name = "stock_take_line")
open class StockTakeLine : BaseEntity<Long>() {
    @NotNull
    @ManyToOne
    @JoinColumn(name = "stockTakeId", nullable = false)
    open var stockTake: StockTake? = null

    @ManyToOne
    @JoinColumn(name = "inventoryLotLineId", nullable = false)
    open var inventoryLotLine: InventoryLotLine? = null

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

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

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

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

//    @Size(max = 20)
    @NotNull
    @Column(name = "status", nullable = false, length = 20)
    @Convert(converter = StockTakeLineStatusConverter::class)
    open var status: StockTakeLineStatus? = null

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

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "stockTakeRecordId")
    open var stockTakeRecord: StockTakeRecord? = null
}