package com.ffii.fpsms.m18.model

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty

/**
 * Request body for M18 Goods Receipt Note (AN) save API.
 * PUT /root/api/save/an?menuCode=an
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
data class GoodsReceiptNoteRequest(
    val mainan: GoodsReceiptNoteMainan,
    val ant: GoodsReceiptNoteAnt,
)

@JsonInclude(JsonInclude.Include.NON_NULL)
data class GoodsReceiptNoteMainan(
    val values: List<GoodsReceiptNoteMainanValue>,
)

@JsonInclude(JsonInclude.Include.NON_NULL)
data class GoodsReceiptNoteMainanValue(
    val id: String? = null,  // "" for create new
    val beId: Int,
    val code: String? = null,  // omit; M18 auto-generates GRN code
    val venId: Int,
    val curId: Int,  // required by M18 (core_101905)
    val rate: Number,
    val status: String? = "Y",
    val docDate: String? = null,
    val tDate: String? = null,  // receiptDate from stock-in line (MM/dd/yyyy)
    val locId: Int? = null,
    val flowTypeId: Int,
    val staffId: Int = 329,
    val cnDeptId: Int? = null,
    val virDeptId: Int? = null,
    val udfMTMSDNNO2: String? = null,  // doNo (dnNo); always include in JSON (use "" when empty) for supplier log audit
    val udfpartiallyreceived: Boolean? = null,  // true if any line acc>=demand, else false
)

@JsonInclude(JsonInclude.Include.NON_NULL)
data class GoodsReceiptNoteAnt(
    val values: List<GoodsReceiptNoteAntValue>,
)

@JsonInclude(JsonInclude.Include.NON_NULL)
data class GoodsReceiptNoteAntValue(
    val sourceType: String,
    val sourceId: Long,
    val sourceLot: String,
    val proId: Int,
    val locId: Int,
    val unitId: Int,
    val qty: Number,
    val up: Number,
    val amt: Number,
    val beId: Int? = null,
    val flowTypeId: Int? = null,
    @JsonProperty("bDesc")
    val itemDesc: String? = null,   // itemName (Chinese); Kotlin property renamed so Jackson outputs "bDesc" not "bdesc"
    @JsonProperty("bDesc_en")
    val itemDescEn: String? = null, // itemName (English); M18 expects exact key "bDesc_en"
)
