package com.muyu.enterprise.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.domain.WarnLogs;
import com.muyu.enterprise.service.WarnLogsService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/logs")
public class WarnLogsController {

    @Autowired
    private WarnLogsService warnLogsService;

    /**
     * 日志列表
     * @return
     */
    @PostMapping("logsList")
    @Operation(summary = "车辆类型列表",description = "车辆类型列表")
    public Result<List<WarnLogs>> logsList(){
        return Result.success(warnLogsService.list());
    }

    /**
     * 根据ID查询日志
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @Operation(summary = "根据ID查询日志", description = "根据ID查询日志")
    public Result getById(@PathVariable("id") Long id){
        return Result.success(warnLogsService.getById(id));
    }

    /**
     * 添加日志
     * @param warnLogs
     * @return
     */
    @PostMapping("logsAdd")
    @Operation(summary = "添加日志",description = "添加日志")
    public Result logsAdd(@Validated @RequestBody WarnLogs warnLogs){
        return Result.success(warnLogsService.save(warnLogs));
    }

    /**
     * 修改日志
     * @param warnLogs
     * @param id
     * @return
     */
    @PostMapping("/{id}")
    @Operation(summary = "修改日志",description = "修改日志")
    public Result logsUpdate(@Validated @RequestBody WarnLogs warnLogs,@PathVariable("id") Long id){
        return Result.success(warnLogsService.updateById(WarnLogs.updateBuilder(warnLogs, () -> id)));
    }

    /**
     * 删除日志
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @Operation(summary = "删除日志",description = "删除日志")
    public Result logsDelete(@PathVariable("id") Long id){
        return Result.success(warnLogsService.removeById(id));
    }

    @DeleteMapping("deleteLogs")
    public Result deleteLogs(@RequestParam("id") Long[] id){
        return Result.success(warnLogsService.removeBatchByIds(Arrays.asList(id)));
    }
}
