package com.muyu.server.controller;



import com.muyu.common.core.domain.Result;
import com.muyu.domain.req.FaultCodeAddReq;
import com.muyu.domain.req.FaultCodeListReq;
import com.muyu.domain.req.FaultCodeUpdReq;
import com.muyu.domain.resp.FaultCodeTotalListResp;
import com.muyu.server.service.FaultCodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 车辆故障码控制层
 * @Author：weiran
 * @Package：com.muyu.cloud.faultmanage.controller
 * @Project：cloud-faultmanage
 * @name：FaultCodeController
 * @Date：2024/9/17 14:51
 */

@RestController
@RequestMapping("/faultcode")
@AllArgsConstructor
@Tag(name = "车辆故障码控制层",description = "从故障信息表中查询数据")
public class FaultCodeController {

    private final FaultCodeService faultCodeService;




    /**
     * 故障码展示(故障码联查)
     * @param faultCodeListReq
     * @return
     */
    @PostMapping("/faultcodelist")
    @Operation(summary = "故障码列表(多)",description = "展示故障码信息")
    public Result<FaultCodeTotalListResp> selectfaultcodelist(@Validated @RequestBody FaultCodeListReq faultCodeListReq){
        FaultCodeTotalListResp selectfaultcodelist = faultCodeService.selectfaultcodelist(faultCodeListReq);
        return Result.success(selectfaultcodelist,"操作成功");
    }


    /**
     * 新增故障码
     * @param faultCodeAddReq
     * @return
     */
    @PostMapping("/faultcodeadd")
    @Operation(summary = "新增故障码",description = "新增故障码信息")
    public Result insertfaultcode(@Validated @RequestBody FaultCodeAddReq faultCodeAddReq){

        faultCodeService.insert(faultCodeAddReq);
        return Result.success(null,"新增成功");
    }

    /**
     * 修改故障码
     * @param faultCodeUpdReq
     * @return
     */
    @PostMapping("/faultcodeupd")
    @Operation(summary = "修改故障码",description = "修改故障码信息")
    public Result updfaultcode(@Validated @RequestBody FaultCodeUpdReq faultCodeUpdReq){
        faultCodeService.upd(faultCodeUpdReq);
        return Result.success(null,"修改成功");
    }

    /**
     * 删除故障码
     * @param messageTypeId
     * @return
     */
    @PostMapping("/faultcodedel/{messageTypeId}")
    @Operation(summary = "删除故障码",description = "删除故障码信息")
    public Result delfaultcode(@PathVariable("messageTypeId") Integer messageTypeId){
        faultCodeService.del(messageTypeId);
        return Result.success(null,"删除成功");
    }

}
