package com.ffii.fpsms.m18.model

import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderType
import java.math.BigDecimal
import java.time.Instant
import java.time.LocalDateTime

/** Purchase Order Response */
data class M18PurchaseOrderResponse (
    val data: M18PurchaseOrderData?,
    val messages: List<M18ErrorMessages>?
)

data class M18PurchaseOrderData (
    val mainpo: List<M18PurchaseOrderMainPo>?,
    val pot: List<M18PurchaseOrderPot>?,
)

data class M18PurchaseOrderMainPo (
    val id: Long,
    val code: String,
    /** M18 user id who created the PO (persisted in [com.ffii.fpsms.m18.entity.M18DataLog.dataLog] via sync reflection). */
    val createUid: Long? = null,
    /** Supplier Id */
    val venId: Long,
    /** ETA */
    val dDate: Long,
    /** Order Date */
    val tDate: Long,
    val lastModifyDate: Long,
    val curId: Long,
    /** Business Unit (Shop) */
    val virDeptId: Long?,
    val beId: Long?,
    val udfIsVoid: Boolean? = false,
)

data class M18PurchaseOrderPot (
    // Purchase Order Line ID
    val id: Long,
    // Purchase Order ID
    val hId: Long,
    // product ID
    val proId: Long,
    val code: String,
    val bDesc: String,
    val unitId: Long,
//    val seriesId: Long?,
    val qty: BigDecimal,
    val up: BigDecimal, // unit price
    val amt: BigDecimal,
    val disc: BigDecimal,
    val lot: String,
)

/** Purchase Order List Response */
data class M18PurchaseOrderListResponseWithType (
    var valuesWithType: MutableList<Pair<PurchaseOrderType, M18PurchaseOrderListResponse?>>,
    var query: String? = null,
)

data class M18PurchaseOrderListResponse (
    var values: List<M18PurchaseOrderListValue>?,
    val messages: List<M18ErrorMessages>?
)

data class M18PurchaseOrderListValue (
    val id: Long,
    val code: String,
    val lastModifyDate: String,

    // Defined by FP-MTMS
    val type: PurchaseOrderType?,
)