package org.wcs.serve.controller.app;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.wcs.model.dto.serve.baseError.QueryBaseErrorReq;
import org.wcs.model.dto.serve.baseError.UpdateBaseErrorReq;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.AppServeResponse;
import org.wcs.model.dto.serve.baseError.AddBaseErrorReq;
import org.wcs.model.vo.serve.baseError.QueryBaseErrorVo;
import org.wcs.model.vo.serve.common.PageDataResponse;
import org.wcs.serve.service.intf.IBaseErrorService;

/**
 * 基础报警资料控制器
 */
@RestController
@RequestMapping("/app/baseError")
@ResponseBody
@RequiredArgsConstructor
public class BaseErrorController {

    private final IBaseErrorService baseErrorService;

    /**
     * 下载导入模板
     * @param response 响应
     */
    @GetMapping("/downloadImportExample")
    public void downLoadImportExample(HttpServletResponse response) {
        baseErrorService.downLoadImportExample(response);
    }

    /**
     * 查询基础错误列表
     * @param request 查询参数
     * @param pageSize 页大小
     * @param pageIndex 页索引
     * @return 查询结果
     */
    @PostMapping("/queryBaseErrorList")
    public AppServeDataResponse<PageDataResponse<QueryBaseErrorVo>> queryBaseErrorList(@RequestBody QueryBaseErrorReq request, @RequestParam("pageSize") Integer pageSize, @RequestParam("pageIndex") Integer pageIndex) {
        return baseErrorService.queryBaseErrorList(request, pageSize, pageIndex);
    }

    /**
     * 添加基础错误
     * @param request 添加基础错误请求参数
     * @return 添加结果
     */
    @PostMapping("/addBaseError")
    public AppServeResponse addBaseError(@RequestBody @Validated AddBaseErrorReq request) {
        return baseErrorService.addBaseError(request);
    }

    /**
     * 导入基础错误
     * @param fileUpload 文件上传
     */
    @PostMapping("/importBaseError")
    public AppServeResponse importBaseError(@RequestParam("file") MultipartFile fileUpload) {
        return baseErrorService.importBaseError(fileUpload);
    }

    /**
     * 删除基础错误
     * @param equipmentType 设备类型
     * @return 删除结果
     */
    @DeleteMapping("/deleteBaseErrorByEquipmentType")
    public AppServeResponse deleteBaseErrorByEquipmentType(@RequestParam("equipmentType") @NotNull(message = "设备类型不能为空") Integer equipmentType) {
        return baseErrorService.deleteBaseErrorByEquipmentType(equipmentType);
    }

    /**
     * 删除基础错误
     * @param id ID
     * @return 删除结果
     */
    @DeleteMapping("/deleteBaseErrorById")
    public AppServeResponse deleteBaseErrorById(@RequestParam("id") @NotNull(message = "ID不能为空") String id) {
        return baseErrorService.deleteBaseErrorById(id);
    }

    /**
     * 修改基础错误
     * @param request 修改基础错误请求参数
     * @return 修改结果
     */
    @PostMapping("/updateBaseError")
    public AppServeResponse updateBaseError(@RequestBody @Validated UpdateBaseErrorReq request) {
        return baseErrorService.updateBaseError(request);
    }

    /**
     * 获取基础错误信息
     * @param equipmentType 设备类型
     * @param errorCode 错误码
     * @return 基础错误信息
     */
    @GetMapping("/getBaseError")
    public AppServeDataResponse<QueryBaseErrorVo> getBaseError(@RequestParam("equipmentType") @NotNull(message = "设备类型不能为空") Integer equipmentType, @RequestParam("errorCode") @NotBlank(message = "错误码不能为空") String errorCode) {
        return baseErrorService.getBaseError(equipmentType, errorCode);
    }





}
