package com.aircraft.modules.order.controller;


import com.aircraft.modules.order.biz.OrderBiz;
import com.aircraft.modules.order.domain.dto.AddOrderDTO;
import com.aircraft.modules.order.domain.dto.AddOrderTaskDTO;
import com.aircraft.modules.order.domain.dto.OrderMainPageQueryDTO;
import com.aircraft.modules.order.domain.dto.UpdateOrderDTO;
import com.aircraft.modules.order.domain.vo.OrderAllDetailVO;
import com.aircraft.modules.order.domain.vo.OrderMainPageQueryVO;
import com.aircraft.modules.system.domain.vo.KeyValueEntity;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 订单主表 前端控制器
 * </p>
 *
 * @author cli
 * @since 2025-07-10
 */
@RestController
@RequestMapping("/api/order")
@Api(tags = "订单管理")
public class OrderMainController {

    @Resource
    private OrderBiz orderBiz;

    @ApiOperation("查询订单列表-多端查询")
    @GetMapping("/allOrder")
    public ResponseEntity<IPage<OrderMainPageQueryVO>>queryOrderList(OrderMainPageQueryDTO pageQueryDTO, Page page) {
        return new ResponseEntity<>(orderBiz.queryAll(pageQueryDTO, page), HttpStatus.OK);
    }

    @ApiOperation("新增订单")
    @PostMapping("/addOrder")
    public ResponseEntity<Object> addOrder(@RequestBody @Validated AddOrderDTO addOrderDTO) {
        orderBiz.addOrder(addOrderDTO);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation("编辑订单")
    @PutMapping("/editOrder")
    public ResponseEntity<Object> editOrder(@RequestBody @Validated UpdateOrderDTO updateOrderDTO) {
        orderBiz.editOrder(updateOrderDTO);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation("删除订单接口")
    @DeleteMapping("/deleteOrder/{orderId}")
    public ResponseEntity<Object> deleteOrder(@PathVariable("orderId") Long orderId) {
        orderBiz.deleteOrder(orderId);
        return new ResponseEntity<>(HttpStatus.OK);
    }


    @ApiOperation("新增订单飞行任务")
    @PostMapping("/addOrderTask")
    public ResponseEntity<Object> addOrderTask(@RequestBody @Validated AddOrderTaskDTO orderTaskDTO) {
        orderBiz.addOrderTask(orderTaskDTO);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation("编辑订单飞行任务状态")
    @PutMapping("/editOrderStatus/{orderTaskId}/{taskStatus}")
    public ResponseEntity<Object> editOrderTaskStatus(
            @ApiParam(value = "订单任务ID", required = true, example = "1946509536383438850")
            @PathVariable("orderTaskId") Long orderTaskId,
            @ApiParam(value = "飞行任务变更状态: 0=未进行中, 1=进行中, 2=已完成, 3=任务失败", required = true, example = "0")
            @PathVariable("taskStatus") Integer taskStatus) {
        orderBiz.editOrderTaskStatus(orderTaskId, taskStatus);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation("删除订单飞行任务")
    @DeleteMapping("/deleteOrderTask/{orderTaskId}")
    public ResponseEntity<Object> deleteOrderTask(
            @ApiParam(value = "订单任务ID", required = true, example = "1946509536383438850")
            @PathVariable("orderTaskId") Long orderTaskId) {
        orderBiz.deleteOrderTask(orderTaskId);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 根据订单ID查询详情
     */
    @ApiOperation("根据订单ID查询详情-多端查询")
    @GetMapping("/queryOrderDetail/{id}")
    public ResponseEntity<OrderAllDetailVO> queryOrderDetail(@PathVariable("id") Long id) {
        return ResponseEntity.ok(orderBiz.queryOrderDetail(id));
    }

    /**
     * 完成订单
     */
    @ApiOperation("完成订单-飞行端&客户端")
    @PutMapping("/completeOrder/{orderId}")
    public ResponseEntity<Object> completeOrder(@PathVariable("orderId") Long orderId) {
        orderBiz.completeOrder(orderId);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 根据订单ID 获取对应的路线下拉-新建订单飞行任务的路线下拉
     */
    @ApiOperation("根据订单ID 获取对应的路线下拉-新建订单飞行任务的路线下拉")
    @GetMapping("/obtainRouteListByOrderId/{orderId}")
    public ResponseEntity<List<KeyValueEntity>> obtainRouteListByOrderId(
            @ApiParam(value = "订单ID", required = true, example = "1946509536383438850")
            @PathVariable("orderId") Long orderId) {
        return ResponseEntity.ok(orderBiz.obtainRouteListByOrderId(orderId));
    }
}

