// FPSMS-backend/src/main/java/com/ffii/fpsms/modules/pickOrder/web/PickExecutionIssueController.kt
package com.ffii.fpsms.modules.pickOrder.web

import com.ffii.fpsms.modules.master.web.models.MessageResponse
import com.ffii.fpsms.modules.pickOrder.entity.PickExecutionIssue
import com.ffii.fpsms.modules.pickOrder.service.PickExecutionIssueService  // ✅ 修复导入路径
import com.ffii.fpsms.modules.stock.web.model.PickExecutionIssueRequest
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/pickExecution")
class PickExecutionIssueController(
    private val pickExecutionIssueService: PickExecutionIssueService
) {

    @PostMapping("/recordIssue")
    fun recordPickExecutionIssue(@RequestBody request: PickExecutionIssueRequest): MessageResponse {
        return pickExecutionIssueService.recordPickExecutionIssue(request)
    }

    @GetMapping("/issues/pickOrder/{pickOrderId}")
    fun getPickExecutionIssuesByPickOrder(@PathVariable pickOrderId: Long): List<PickExecutionIssue> {
        return pickExecutionIssueService.getPickExecutionIssuesByPickOrder(pickOrderId)
    }

    @GetMapping("/issues/pickOrderLine/{pickOrderLineId}")
    fun getPickExecutionIssuesByPickOrderLine(@PathVariable pickOrderLineId: Long): List<PickExecutionIssue> {
        return pickExecutionIssueService.getPickExecutionIssuesByPickOrderLine(pickOrderLineId)
    }
    @GetMapping("/issues/all")
    fun getAllPickExecutionIssues(
        @RequestParam(required = false) type: String?
    ): List<PickExecutionIssue> {
        println("=== Controller received type parameter: $type ===")
        return pickExecutionIssueService.getAllPickExecutionIssues(type)
    }
}