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

import com.ffii.fpsms.modules.pickOrder.service.PickOrderLifecycleService
import com.ffii.fpsms.modules.pickOrder.web.models.PickOrderLifecycleResponse
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/pickOrder")
class PickOrderLifecycleController(
    private val lifecycleService: PickOrderLifecycleService,
) {
    /** FP-MTMS Version Checklist | Functions Ref. No. 11 | v1.0.0 | 2026-07-17 */
    @GetMapping("/{id}/lifecycle")
    fun getLifecycle(@PathVariable id: Long): ResponseEntity<PickOrderLifecycleResponse> {
        val result = lifecycleService.getLifecycle(id)
        return if (result != null) ResponseEntity.ok(result)
        else ResponseEntity.notFound().build()
    }

    /** FP-MTMS Version Checklist | Functions Ref. No. 11 | v1.0.0 | 2026-07-17 */
    @GetMapping("/lifecycle/by-code")
    fun getLifecycleByCode(@RequestParam code: String): ResponseEntity<PickOrderLifecycleResponse> {
        val result = lifecycleService.getLifecycleByCode(code)
        return if (result != null) ResponseEntity.ok(result)
        else ResponseEntity.notFound().build()
    }
}
