package com.ffii.fpsms.modules.pickOrder.web.models

import org.springframework.web.bind.annotation.RequestParam
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.LocalDate
import java.math.BigDecimal
data class SearchPickOrderRequest (
    val code: String?,
    val targetDateFrom: String?,
    val targetDateTo: String?,
    val type: String?,
    val status: String?,
    val itemName: String?,
    val pageSize: Int?,
    val pageNum: Int?,
    /** When set, restrict to pick orders assigned to this user id. */
    val assignTo: Long? = null,
)
data class GetCompletedDoPickOrdersRequest(
    val targetDate: String? = null,
    val shopName: String? = null,
    val deliveryNoteCode: String? = null,
    /** 卡車 / 車道代碼（模糊匹配 truck_lance_code） */
    val truckLanceCode: String? = null,
    val ticketNo: String? = null,
)

data class CompletedDoPickOrderResponse(
    val id: Long,
    val doPickOrderRecordId: Long,
    val recordId: Long,
    val ticketNo: String,
    val storeId: String?,
    val completedDate: String?,
    val shopCode: String?,
    val shopName: String?,
    val deliveryNoteCode: String?,
    val truckLanceCode: String?,
    val departureTime: LocalTime?,
    val pickOrderIds: List<Long>,
    val pickOrderCodes: List<String>,
    val deliveryOrderIds: List<Long>,
    val deliveryNos: List<String>,
    val pickOrderConsoCode: String?,
    val pickOrderStatus: String?,
    val deliveryDate: String?,
    val numberOfCartons: Int,
    val shopId: Long?,
    val shopAddress: String?,
    val fgPickOrders: List<FgPickOrderSummary>,
    /** Legacy: `do_pick_order_record.handler_name`; workbench: `delivery_order_pick_order.handlerName`. */
    val handlerName: String? = null,
)

data class FgPickOrderSummary(
    val pickOrderId: Long,
    val deliveryOrderId: Long?
)
data class LotDetailsByDoPickOrderRecordResponse(
    val fgInfo: FgInfoResponse?,
    val pickOrders: List<PickOrderDetailResponse>
)

data class FgInfoResponse(
    val doPickOrderId: Long?,
    val ticketNo: String?,
    val storeId: String?,
    val shopCode: String?,
    val shopName: String?,
    val truckLanceCode: String?,
    val departureTime: LocalTime?
)
data class HierarchicalPickOrderResponse(
    val fgInfo: FgInfoResponse?,
    val pickOrders: List<PickOrderDetailResponse>,
    val totalLines: Int,
    val pageNum: Int,
    val pageSize: Int,
    val scannedItemsCount: Int? = null,
    val totalItemsCount: Int? = null
)

data class PickOrderDetailResponse(
    val pickOrderId: Long?,
    val pickOrderCode: String?,
    val doOrderId: Long?,
    val deliveryOrderCode: String?,
    val consoCode: String?,
    val status: String?,
    val targetDate: LocalDate?,
    val pickOrderLines: List<PickOrderLineDetailResponse>
)

data class PickOrderLineDetailResponse(
    val id: Long?,
    val requiredQty: BigDecimal?,
    val status: String?,
    val item: ItemInfoResponse,
    val lots: List<LotDetailResponse>,
    val stockouts: List<StockOutDetailResponse>
)

data class ItemInfoResponse(
    val id: Long?,
    val code: String?,
    val name: String?,
    val uomCode: String?,
    val uomDesc: String?,
    val uomShortDesc: String?
)

data class LotDetailResponse(
    val id: Long?,
    val lotNo: String?,
    val expiryDate: LocalDate?,
    val location: String?,
    val stockUnit: String?,
    val availableQty: BigDecimal?,
    val requiredQty: BigDecimal?,
    val actualPickQty: BigDecimal?,
    val inQty: BigDecimal?,
    val outQty: BigDecimal?,
    val holdQty: BigDecimal?,
    val lotStatus: String?,
    val lotAvailability: String?,
    val processingStatus: String?,
    val suggestedPickLotId: Long?,
    val stockOutLineId: Long?,
    val stockOutLineStatus: String?,
    val stockOutLineQty: BigDecimal?,
    val router: RouterInfoResponse
)

data class RouterInfoResponse(
    val id: Long?,
    val index: String?,
    val route: String?,
    val area: String?
)

data class StockOutDetailResponse(
    val id: Long?,
    val status: String?,
    val qty: BigDecimal?,
    val lotId: Long?,
    val lotNo: String?,
    val location: String?,
    val availableQty: BigDecimal?,
    val noLot: Boolean
)

data class DoPickOrderRequest(
    val userId: Long,
    val pageSize: Int?,
    val pageNum: Int?,
)