// StockTakeRecordReponse.kt
package com.ffii.fpsms.modules.stock.web.model
import com.fasterxml.jackson.annotation.JsonFormat
import java.time.LocalDate
import java.math.BigDecimal
import java.time.LocalDateTime
import com.ffii.core.response.RecordsRes

data class AllPickedStockTakeListReponse(
    val id: Long,
    val stockTakeSession: String,
    @JsonFormat(pattern = "yyyy-MM-dd")
    val lastStockTakeDate: LocalDate?,
    val status: String,
    val currentStockTakeItemNumber: Int,
    val totalInventoryLotNumber: Int,
    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
    val startTime: LocalDateTime?,
    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
    val endTime: LocalDateTime?,
    val stockTakeId: Long,
    val stockTakerName: String?,
    val approverName: String?,
    val TotalItemNumber: Int,
    val ReStockTakeTrueFalse: Boolean,
    @JsonFormat(pattern = "yyyy-MM-dd")
    val planStartDate: LocalDate?,
)
data class InventoryLotDetailResponse(
    val id: Long,
    val inventoryLotId: Long,
    val itemId: Long,
    val itemCode: String?,
    val itemName: String?,
    val lotNo: String?,
    val expiryDate: LocalDate?,
    val productionDate: java.time.LocalDateTime?,
    val stockInDate: java.time.LocalDateTime?,
    val inQty: BigDecimal?,
    val outQty: BigDecimal?,
    val holdQty: BigDecimal?,
    val availableQty: BigDecimal?,
    val uom: String?,
    val warehouseCode: String?,
    val warehouse: String?,
    val warehouseSlot: String?,
    val warehouseArea: String?,
    val warehouseName: String?,
    val varianceQty: BigDecimal? = null,
    val status: String?,
    val remarks: String?,
    val stockTakeRecordStatus: String?,
    val stockTakeRecordId: Long? = null, 
    val firstStockTakeQty: BigDecimal? = null, 
    val secondStockTakeQty: BigDecimal? = null, 
    val firstBadQty: BigDecimal? = null, 
    val secondBadQty: BigDecimal? = null, 
    val approverQty: BigDecimal? = null,
    val approverBadQty: BigDecimal? = null,
    val finalQty: BigDecimal? = null,
    val bookQty: BigDecimal? = null,
)
data class InventoryLotLineListRequest(
    val warehouseCode: String
)
data class SaveStockTakeRecordRequest(
    val stockTakeRecordId: Long? = null, // null = 创建，非 null = 更新
    val inventoryLotLineId: Long, // 创建时需要，用于识别 inventory lot line
    val qty: BigDecimal, // QTY（第一次或第二次，后端判断）
    val badQty: BigDecimal,
  //  val stockTakerName: String,
    val remark: String? = null
)
data class SaveApproverStockTakeRecordRequest(
    val stockTakeRecordId: Long? = null, 
    val qty: BigDecimal, 
    val badQty: BigDecimal,
    val approverId: Long? = null,
    val approverQty: BigDecimal? = null,
    val approverBadQty: BigDecimal? = null,
    //val remark: String? = null
)
data class BatchSaveStockTakeRecordRequest(
    val stockTakeId: Long,
    val stockTakeSection: String,
    val stockTakerId: Long,
    //val stockTakerName: String
)

data class BatchSaveStockTakeRecordResponse(
    val successCount: Int,
    val errorCount: Int,
    val errors: List<String>
)
data class BatchSaveApproverStockTakeRecordRequest(
    val stockTakeId: Long,
    val stockTakeSection: String,
    val approverId: Long,
    val variancePercentTolerance: BigDecimal? = null,
)

data class BatchSaveApproverStockTakeRecordResponse(
    val successCount: Int,
    val errorCount: Int,
    val errors: List<String>
)
data class SearchStockTransactionRequest(
    val startDate: LocalDate? = null,
    val endDate: LocalDate? = null,
    val itemCode: String? = null,
    val itemName: String? = null,
    val type: String? = null,
    val pageNum: Int = 0,
    val pageSize: Int = 100
)
data class StockTransactionResponse(
    val id: Long,
    val transactionType: String, 
    val itemId: Long,
    val itemCode: String?,
    val itemName: String?,
    val balanceQty: BigDecimal? = null,
    val qty: BigDecimal,
    val type: String?, 
    val date: LocalDate?,
    val status: String,
    val transactionDate: LocalDateTime?, 
    val lotNo: String?,
    val stockInId: Long?,
    val stockOutId: Long?,
    val remarks: String?
)

data class StockTransactionListResponse(
    val records: RecordsRes<StockTransactionResponse>
)