package cn.iocoder.yudao.module.app.order.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.order.entity.RepairOrderInfo;
import cn.iocoder.yudao.module.order.service.RepairOrderInfoService;
import cn.iocoder.yudao.module.order.vo.RepairOrderInfoRespVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 维修订单API
 *
 * @author 小李
 * @date 17:20 2024/9/23
**/
@RestController
@RequestMapping("/userClient/repair/order")
public class RepairOrderAPI {

    @Resource
    @Lazy
    private RepairOrderInfoService repairOrderInfoService;

    /**
     * 订单分页查询
     *
     * @author 小李
     * @date 17:35 2024/9/23
     * @param respVO 查询对象
     * @param pageNo 页码
     * @param pageSize 条数
    **/
    @GetMapping("/page")
    @Operation(summary = "订单分页查询")
    public CommonResult<?> getOrderPageByStatus(RepairOrderInfoRespVO respVO,
                                                @RequestParam(value = "pageNo", defaultValue = "1")Integer pageNo,
                                                @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize){
        Page<RepairOrderInfo> page = new Page<>(pageNo, pageSize);
        return success(repairOrderInfoService.getOrderPageByStatus(respVO, page));
    }

    /**
     * 查询订单详情(包括工单)
     *
     * @author 小李
     * @date 17:43 2024/9/23
     * @param id 订单ID
    **/
    @GetMapping("/get")
    @Operation(summary = "查询订单详情")
    public CommonResult<?> getOrderById(@RequestParam(value = "id") String id){
        return success(repairOrderInfoService.getOrderById(id));
    }

    /**
     * 评价订单
     *
     * @author 小李
     * @date 17:50 2024/9/23
     * @param respVO 请求对象
    **/
    @PostMapping("/appraise")
    @Operation(summary = "评价订单")
    public CommonResult<?> appraiseOrder(@RequestBody RepairOrderInfoRespVO respVO){
        repairOrderInfoService.appraiseOrder(respVO);
        return CommonResult.ok();
    }

    /**
     * 获得已经评价的订单
     *
     * @author 小李
     * @date 15:50 2024/9/24
     * @param pageNo 页码
     * @param pageSize 条数
    **/
    @GetMapping("/getAppraise")
    @Operation(summary = "获得已经评价的订单")
    public CommonResult<?> getAppraisePage(@RequestParam(value = "pageNo", defaultValue = "1")Integer pageNo,@RequestParam(value = "pageSize",defaultValue = "1")Integer pageSize){
        Page<RepairOrderInfo> page = new Page<>(pageNo, pageSize);
        return success(repairOrderInfoService.getAppraisePage(page));
    }
}
