package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.iot.domain.CrmDeviceRepair;
import com.usky.iot.service.CrmDeviceRepairService;
import com.usky.iot.service.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 设备报修记录表 前端控制器
 * </p>
 *
 * @author han
 * @since 2023-09-06
 */
@RestController
@RequestMapping("/crmDeviceRepair")
public class CrmDeviceRepairController {
    @Autowired
    private CrmDeviceRepairService crmDeviceRepairService;

    /**
     * 报修申请
     * @param crmDeviceRepair
     * @return
     */
    @PostMapping("add")
    ApiResult<Void> add(@RequestBody CrmDeviceRepair crmDeviceRepair){
        crmDeviceRepairService.add(crmDeviceRepair);
        return ApiResult.success();
    }

    /**
     * 分页
     * @param crmDeviceRepairVO
     * @return
     */
    @PostMapping("page")
    ApiResult<CommonPage<CrmDeviceRepair>> page(@RequestBody CrmDeviceRepairVO crmDeviceRepairVO){
        return ApiResult.success(crmDeviceRepairService.page(crmDeviceRepairVO));
    }

    @PostMapping("statistic")
    ApiResult<List<CrmDeviceRepairStatisticVO>> statistic(@RequestBody CrmDeviceRepairVO crmDeviceRepairVO){
        return ApiResult.success(crmDeviceRepairService.statistic(crmDeviceRepairVO));
    }

    /**
     * 获取项目历史信息
     *
     * @param projectName   项目名称
     * @return
     */
    @GetMapping("getAddHistoryInfo")
    ApiResult<List<CrmDeviceRepairAddVO>> getAddHistoryInfo(@RequestParam(value = "projectName") String projectName){
        return ApiResult.success(crmDeviceRepairService.getAddHistoryInfo(projectName));
    }


    /**
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    ApiResult<Void> remove(@PathVariable("id") Integer id){
        crmDeviceRepairService.remove(id);
        return ApiResult.success();
    }

    /**
     * 填报
     * @param crmDeviceRepair
     * @return
     */
    @PostMapping("fill")
    ApiResult<Void> fill(@RequestBody CrmDeviceRepair crmDeviceRepair){
        crmDeviceRepairService.fill(crmDeviceRepair);
        return ApiResult.success();
    }

    /**
     * 服务评价
     * @param scoreVO
     * @return
     */
    @PostMapping("score")
    ApiResult<Void> score(@RequestBody CrmDeviceRepairScoreVO scoreVO){
        crmDeviceRepairService.score(scoreVO);
        return ApiResult.success();
    }

    /**
     * 手机号校验
     * @param phoneVerifyVO
     * @return
     */
    @PostMapping("phoneVerify")
    ApiResult<Void> phoneVerify(@RequestBody PhoneVerifyVO phoneVerifyVO){
        crmDeviceRepairService.phoneVerify(phoneVerifyVO);
        return ApiResult.success();
    }

    /**
     * 获取每个手机号提交的历史记录
     * @param phoneVerifyVO
     * @return
     */
    @PostMapping("getHistory")
    ApiResult<CommonPage<CrmDeviceRepair>> getHistory(@RequestBody PhoneVerifyVO phoneVerifyVO){
        return ApiResult.success(crmDeviceRepairService.getHistory(phoneVerifyVO));
    }
}

