package com.cmvr.web.controller.ti;

import com.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.ti.model.domain.TiVehicleConfig;
import com.cmvr.ti.model.vo.TiVehicleConfigTreeVO;
import com.cmvr.ti.service.ITiVehicleConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "触控交互--车辆配置")
@RestController
@RequestMapping("/ti/config")
@RequiredArgsConstructor
public class TiVehicleConfigController extends BaseController {

    private final ITiVehicleConfigService tiVehicleConfigService;

    @ApiOperation("查询车辆配置列表")
    @PreAuthorize("@ss.hasPermi('ti:config:list')")
    @GetMapping("/list")
    public List<TiVehicleConfigTreeVO> list() {
         return tiVehicleConfigService.selectTiVehicleConfigList();
    }

    @ApiOperation("获取车辆配置详细信息")
    @PreAuthorize("@ss.hasPermi('ti:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tiVehicleConfigService.selectTiVehicleConfigById(id));
    }

    @ApiOperation("新增车辆配置")
    @PreAuthorize("@ss.hasPermi('ti:config:add')")
    @Log(title = "车辆配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TiVehicleConfig tiVehicleConfig) {
        return toAjax(tiVehicleConfigService.insertTiVehicleConfig(tiVehicleConfig));
    }

    @ApiOperation("修改车辆配置")
    @PreAuthorize("@ss.hasPermi('ti:config:edit')")
    @Log(title = "车辆配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TiVehicleConfig tiVehicleConfig) {
        return toAjax(tiVehicleConfigService.updateTiVehicleConfig(tiVehicleConfig));
    }

    @ApiOperation("删除车辆配置")
    @PreAuthorize("@ss.hasPermi('ti:config:remove')")
    @Log(title = "车辆配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tiVehicleConfigService.deleteTiVehicleConfigByIds(ids));
    }
}
