package com.muyu.server.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.domain.SysCar;
import com.muyu.common.domain.req.SysCarReq;
import com.muyu.common.domain.resp.SysCarFaultLogVo;
import com.muyu.server.service.SysCarService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆管理
 * @author sx
 * @Package：com.template.controller
 * @name：SysCarController
 * @Date：2024/9/20 12:12
 */
@RestController
@RequestMapping("/sysCar")
@AllArgsConstructor
@Tag(name = "车辆管理",description = "车辆类型管理")
@Log4j2
public class SysCarController {
    @Autowired
    private SysCarService sysCarService;

    /**
     * 车辆列表
     * @param sysCarReq 参数
     * @return
     */
    @PostMapping("/selectSysCarVoList")
    @Operation(summary = "车辆列表",description = "车辆列表")
    public Result selectSysCarVoList(@RequestBody SysCarReq sysCarReq){
        return Result.success(sysCarService.selectSysCarVoList(sysCarReq));
    }


    /**
     * 车辆列表
     * @param id 参数
     * @return
     */
    @GetMapping("/selectSysCarVoById/{id}")
    @Operation(summary = "根据ID查询车辆列表",description = "根据ID查询车辆列表")
    public Result selectSysCarVoById(@PathVariable("id") Long id){
        return Result.success(sysCarService.selectSysCarVoById(id));
    }


    @PostMapping("/addSysCar")
    @Operation(summary = "车辆添加",description = "车辆添加")
    public Result addSysCar(@RequestBody SysCar sysCar){
        return Result.success(sysCarService.addSysCar(sysCar));
    }

    @PostMapping("/updateSysCar")
    @Operation(summary = "车辆修改",description = "车辆修改")
    public Result updateSysCar(@RequestBody SysCar sysCar){
        return Result.success(sysCarService.updateSysCar(sysCar));
    }


    @DeleteMapping("/deleteSysCarById/{id}")
    @Operation(summary = "车辆删除",description = "车辆删除")
    public Result deleteSysCarById(@PathVariable("id") Long id){
        int i = sysCarService.deleteSysCarById(id);
        return i>0?Result.success():Result.error();
    }

    /**
     * 根据车辆的VIN码查询该车的故障记录
     * @param carVin
     * @return
     */
    @PostMapping("/findFenceByCarVin/{carVin}")
    @Operation(summary = "根据车辆的VIN码查询该车的故障记录",description = "根据车辆的VIN码查询该车的故障记录")
    public Result<List<SysCarFaultLogVo>> findFenceByCarVin(@PathVariable("carVin") String carVin){
        return Result.success(sysCarService.findFenceByCarVin(carVin));
    }

    /**
     * 根据VIN码查询车信息
     * @param carVin
     * @return
     */
    @PostMapping("/findCarByVin")
    @Operation(summary = "根据VIN码查询车信息",description = "根据VIN码查询车信息")
    public Result<SysCar> findCarByVin(@RequestParam("carVin") String carVin){
        return Result.success(sysCarService.findCarByVin(carVin));
    }

}
