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

import com.fasterxml.jackson.annotation.JsonBackReference
import com.fasterxml.jackson.annotation.JsonIdentityInfo
import com.fasterxml.jackson.annotation.ObjectIdGenerators
import com.ffii.core.entity.BaseEntity
import com.ffii.fpsms.modules.master.entity.Items
import jakarta.persistence.*
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import org.hibernate.annotations.JdbcTypeCode
import org.hibernate.type.SqlTypes
import java.time.LocalDate
import java.time.LocalDateTime

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator::class, property = "id")
@Entity
@Table(name = "inventory_lot")
open class InventoryLot : BaseEntity<Long>() {
    @NotNull
    @OneToOne
    @JoinColumn(name = "itemId", nullable = false)
    open var item: Items? = null

    @JsonBackReference
    @NotNull
    @ManyToOne
    @JoinColumn(name = "stockInLineId", nullable = false)
    open var stockInLine: StockInLine? = null

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

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

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

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

    @OneToMany(mappedBy = "inventoryLot", cascade = [CascadeType.ALL], orphanRemoval = true)
    open var inventoryLotLines: MutableList<InventoryLotLine>? = null

//    @JdbcTypeCode(SqlTypes.JSON)
//    @Column(name = "qrCodeJson")
//    open var qrCodeJson: MutableMap<String, Any>? = null
}