package com.ffii.fpsms.modules.deliveryOrder.web

import com.ffii.fpsms.modules.deliveryOrder.entity.DeliveryOrder
import com.ffii.fpsms.modules.deliveryOrder.entity.models.DeliveryOrderInfo
import com.ffii.fpsms.modules.deliveryOrder.enums.DeliveryOrderStatus
import com.ffii.fpsms.modules.deliveryOrder.service.DeliveryOrderService
import com.ffii.fpsms.modules.deliveryOrder.web.models.SaveDeliveryOrderRequest
import com.ffii.fpsms.modules.deliveryOrder.web.models.SaveDeliveryOrderResponse
import com.ffii.fpsms.modules.deliveryOrder.web.models.SaveDeliveryOrderStatusRequest
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RequestMapping("/do")
@RestController
class DeliveryOrderController(
    private val deliveryOrderService: DeliveryOrderService,
) {
    @GetMapping("/list")
    fun getDoList(): List<DeliveryOrderInfo> {
        return deliveryOrderService.getDoList();
    }

    @GetMapping("/detail/{id}")
    fun getDetailedDo(@PathVariable id: Long): DeliveryOrder? {
        return deliveryOrderService.getDetailedDo(id);
    }

    @PostMapping("/update-status")
    fun updateDoStatus(@RequestBody request: SaveDeliveryOrderStatusRequest): SaveDeliveryOrderResponse {
        return deliveryOrderService.updateDeliveryOrderStatus(request);
    }

    @PostMapping("/start")
    fun startDo(@RequestBody id: Long): SaveDeliveryOrderResponse {
        val request = SaveDeliveryOrderStatusRequest(
            id = id,
            status = DeliveryOrderStatus.RECEIVING.value
        )
        return deliveryOrderService.updateDeliveryOrderStatus(request);
    }
}