package com.ffii.fpsms.modules.purchaseOrder.entity.projections

import com.fasterxml.jackson.annotation.JsonManagedReference
import com.ffii.fpsms.modules.master.entity.ItemUom
import com.ffii.fpsms.modules.master.entity.QcItem
import com.ffii.fpsms.modules.master.entity.UomConversion
import com.ffii.fpsms.modules.stock.entity.StockInLine
import com.ffii.fpsms.modules.stock.entity.projection.StockInLineInfo
import jakarta.persistence.CascadeType
import jakarta.persistence.OneToMany
import org.springframework.beans.factory.annotation.Value
import java.math.BigDecimal

interface PurchaseOrderLineInfo {
    val id: Long
    @get:Value("#{target.purchaseOrder.id}")
    val purchaseOrderId: Long
    val itemNo: String
    @get:Value("#{target.items?.name}")
    val itemName: String?
    val qty: BigDecimal
    @get:Value("#{target.uom}")
    val uom: UomConversion
    val price: BigDecimal
    val status: String
}

data class PoLineWithStockInLine (
    val id: Long,
    val purchaseOrderId: Long,
    val itemId: Long,
    val itemNo: String,
    val itemName: String?,
    val qty: BigDecimal,
    @get:Value("#{target.stockInLines.?[].inventoryLot.?[].inventoryLotLines.?[inQty != null][].inQty.sum()}")
    val processed: BigDecimal,
    val receivedQty: BigDecimal,
    @get:Value("#{target.uom}")
    val uom: UomConversion,
    val stockUom: StockUomForPoLine,
    val price: BigDecimal,
    val status: String,

    val stockInLine: List<StockInLineInfo>?,

    val qcItems: List<QcForPoLine>
)

data class QcForPoLine (
    val id: Long?,
    val code: String?,
    val name: String?,
    val description: String?,
)

data class StockUomForPoLine (
    val id: Long? = null,
    val stockUomCode: String? = null,
    val stockUomDesc: String? = null,
    val stockQty: BigDecimal? = null,
    val stockRatioN: BigDecimal? = null,
    val stockRatioD: BigDecimal? = null,
    val purchaseRatioN: BigDecimal? = null,
    val purchaseRatioD: BigDecimal? = null,
)