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

import com.ffii.fpsms.modules.master.entity.*
import org.springframework.beans.factory.annotation.Value
import java.math.BigDecimal
import java.time.LocalDateTime

// Job Orders
interface JobOrderInfo {
    val id: Long;
    val code: String;

    @get:Value("#{target.bom.item.code}")
    val itemCode: String;
    @get:Value("#{target.bom.item.name}")
    val itemName: String;
    @get:Value("#{target.bom.name}")
    val name: String;
    val reqQty: BigDecimal;

    @get:Value("#{target.bom.item}")
    val item: JobOrderItemInfo;

    // TODO pack below as StockInLineInfo
    @get:Value("#{target.stockInLines?.size() > 0 ? target.stockInLines[0].id : null}")
    val stockInLineId: Long?;

    @get:Value("#{target.stockInLines?.size() > 0 ? target.stockInLines[0].status : null}")
    val stockInLineStatus: String?;

    @get:Value("#{target.stockInLines?.size() > 0 ? target.stockInLines[0].escalationLog.^[status.value == 'pending']?.handler?.id : null}")
    val silHandlerId: Long?;
    @get:Value("#{target.stockInLines?.size() > 0 ? target.stockInLines[0].lotNo : null}")
    val lotNo: String?
    val planStart: LocalDateTime?;
//    @get:Value("#{target.bom.item.itemUoms.^[salesUnit == true && deleted == false]?.uom}")
////    @get:Value("#{target.bom.item.itemUoms.^[salesUnit == true && deleted == false]?.uom.udfudesc}")
//    val uom: UomConversion;
    @get:Value("#{target.productProcess?.productionPriority}")
    val productionPriority: Int?;
    @get:Value("#{target.status.value}")
    val status: String;

    @get:Value("#{target.jobTypeId}")
    val jobTypeId: Long?;
    
    
}
data class JobTypeResponse(
    val id: Long?,
    val name: String?
)
data class JobOrderInfoWithTypeName(
    val id: Long,
    val code: String,
    val itemCode: String,
    val itemName: String,
    val name: String,
    val reqQty: BigDecimal,
    val item: JobOrderItemInfo,
    val stockInLineId: Long?,
    val stockInLineStatus: String?,
    val sufficientCount: Int?,
    val insufficientCount: Int?,
    val silHandlerId: Long?,
    val planStart: LocalDateTime?,
    val productionPriority: Int?,
    val status: String,
    val jobTypeId: Long?,
    val jobTypeName: String?,
    val lotNo: String?
)
// Job Order
interface JobOrderDetailWithJsonString {
    val id: Long?;
    val code: String?;
    val itemCode: String?;
    val name: String?;
    val bomId: Long?;
    val itemId: Long?;
    val reqQty: BigDecimal?;
    val uom: String?;
    val shortUom: String?;
    val pickLines: String?;
    val status: String?;
}

//interface JobOrderResult {
//    val id: Long;
//    val code: String?;
//    @get:Value("#{target.status.value}")
//    val status: String;
//    @get:Value("#{target.bom.item}")
//    val item: Items;
//    val reqQty: BigDecimal;
//    @get:Value("#{target.bom.item.itemUoms.^[salesUnit == true && deleted == false]?.uom}")
//    val uom: UomConversion?;
//}

interface JobOrderItemInfo{
    val id: Long
    val name: String
    val code: String
    val description: String?
    val remarks: String?
    val type: String?
    val shelfLife: Double?
    val countryOfOrigin: String?
    val maxQty: Double?
    @get:Value("#{target.itemUoms.^[salesUnit == true && deleted == false]?.uom}")
    val uom: UomConversion?
}

data class JobOrderDetail(
    val id: Long?,
    val code: String?,
    val itemCode: String?,
    val name: String?,
    val bomId: Long?,
    val reqQty: BigDecimal?,
    val uom: String?,
    val shortUom: String?,
    val pickLines: List<JobOrderDetailPickLine>?,
    val status: String?
)

data class JobOrderDetailPickLine(
    val id: Long?,
    val code: String?,
    val name: String?,
    val pickedLotNo: List<JobOrderDetailPickedLotNo>?,
    val type: String?,
    val reqQty: BigDecimal?,
    val uom: String?,
    val shortUom: String?,
    val status: String?
)

data class JobOrderDetailPickedLotNo(
    val lotNo: String?,
    val qty: BigDecimal?,
)