package com.yuchen.saas.park.service.controller.repair;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.repair.*;
import com.yuchen.saas.park.api.vo.repair.PmgBatRepairAddressRecordVO;
import com.yuchen.saas.park.api.vo.repair.SaasMatterRepairListVo;
import com.yuchen.saas.park.api.vo.repair.SaasMatterRepairVo;
import com.yuchen.saas.park.service.service.repair.ISaasMatterRepairService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报事报修表 前端控制器
 *
 * @author caiwq
 * @since 2024-04-24
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/matterRepair")
public class SaasMatterRepairController {

    private final ISaasMatterRepairService baseService;

    /**
     * 新增报事报修
     * @param matterRepairDto 报事报修Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/add")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增报事报修", notes = "新增报事报修")
    public R<Boolean> add(@RequestBody @Validated SaasMatterRepairDto matterRepairDto) {
        return R.data(baseService.add(matterRepairDto));
    }

    /**
     * 新增报事报修
     * @param dto repairUserId
     */
    @PostMapping("/address/records")
    @ApiOperation(value = "报事报修地点记录", notes = "报事报修地点记录")
    public R<List<PmgBatRepairAddressRecordVO>> addressRecords(@RequestBody PmgBatRepairAddressRecordQueryDTO dto) {
        return R.data(baseService.addressRecords(dto));
    }

    /**
     * 受理
     * @param acceptDto 受理Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/accept")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "受理", notes = "受理")
    public R<Boolean> accept(@RequestBody @Validated SaasMatterRepairAcceptDto acceptDto) {
        return R.data(baseService.accept(acceptDto));
    }

    /**
     * 派工
     * @param dispatchDto 受理Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/dispatch")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "派工", notes = "派工")
    public R<Boolean> dispatch(@RequestBody @Validated SaasMatterRepairDispatchDto dispatchDto) {
        return R.data(baseService.dispatch(dispatchDto));
    }

    /**
     * 回访
     * @param backDto 回访Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/back")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "回访", notes = "回访")
    public R<Boolean> back(@RequestBody @Validated SaasMatterRepairBackDto backDto) {
        return R.data(baseService.back(backDto));
    }


    /**
     * 作废/关闭
     * @param cancleDto 取消报修Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/cancle")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "作废/关闭", notes = "作废/关闭")
    public R<Boolean> cancle(@RequestBody @Validated SaasMatterRepairCancleDto cancleDto) {
        return R.data(baseService.cancle(cancleDto));
    }


    /**
     * 报修评价
     * @param evaluateDto 评价Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/evaluate")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "报修评价", notes = "报修评价")
    public R<Boolean> evaluate(@RequestBody @Validated SaasMatterRepairEvaluateDto evaluateDto) {
        return R.data(baseService.evaluate(evaluateDto));
    }

    /**
     * 删除
     * @param id 主键ID
     * @return TRUE/FALSE
     */
    @DeleteMapping("/remove/{id}")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "删除", notes = "删除")
    public R<Boolean> remove(@ApiParam(name = "id", value = "主键ID", required = true) @PathVariable("id") Long id) {
        return R.data(baseService.remove(id));
    }

    /**
     * 报事报修详情
     * @param id 消息ID
     * @return 消息详情Vo
     */
    @GetMapping("/getDetail/{id}")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "报事报修详情", notes = "报事报修详情")
    public R<SaasMatterRepairVo> getDetail(@ApiParam(name = "id", value = "主键ID", required = true) @PathVariable("id") Long id) {
        return R.data(baseService.getDetail(id));
    }

    /**
     * 报事报修列表(分页)
     * @param queryDto 报事报修工单列表查询参数
     * @return 报事报修工单列表Vo
     */
    @PostMapping("/list")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "报事报修列表(分页)", notes = "报事报修列表(分页)")
    public R<NestPage<SaasMatterRepairListVo>> getMatterRepairList(@RequestBody SaasMatterRepairQueryDto queryDto) {
        return R.data(baseService.getMatterRepairList(queryDto));
    }

    /**
     * 导出报事报修
     * @return page 分页数据
     */
    @PostMapping("/export")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "导出报事报修", notes = "导出报事报修")
    public void export(@RequestBody SaasMatterRepairQueryDto queryDto, HttpServletResponse response) {
        baseService.export(queryDto, response);
    }

}
