package com.muyu.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.domain.SysCar;
import com.muyu.domain.SysCarFaultLog;
import com.muyu.domain.req.SysCarReq;

import com.muyu.domain.resp.SysCarFaultLogVo;
import com.muyu.service.SysCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/sysCar")
public class SysCarController {
    @Autowired
    private SysCarService sysCarService;

    @PostMapping("/selectSysCarVoList")
    public Result selectSysCarVoList(@RequestBody SysCarReq sysCarReq){
        return Result.success(sysCarService.selectSysCarVoList(sysCarReq));
    }


    @GetMapping("/selectSysCarVoById/{id}")
    public Result selectSysCarVoById(@PathVariable("id") Long id){
        return Result.success(sysCarService.selectSysCarVoById(id));
    }


    @PostMapping("/addSysCar")
    public Result addSysCar(@RequestBody SysCar sysCar){
        return Result.success(sysCarService.addSysCar(sysCar));
    }

    @PostMapping("/updateSysCar")
    public Result updateSysCar(@RequestBody SysCar sysCar){
        return Result.success(sysCarService.updateSysCar(sysCar));
    }


    @DeleteMapping("/deleteSysCarById/{id}")
    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}")
    public Result<List<SysCarFaultLogVo>> findFenceByCarVin(@PathVariable("carVin") String carVin){
        return Result.success(sysCarService.findFenceByCarVin(carVin));
    }

}
