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.core.page.TableDataInfo;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.ti.model.domain.TiVehicleFunction;
import com.cmvr.ti.model.vo.TiVehicleFunctionVO;
import com.cmvr.ti.service.ITiVehicleFunctionService;
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/function")
@RequiredArgsConstructor
public class TiVehicleFunctionController extends BaseController {
    private final ITiVehicleFunctionService tiVehicleFunctionService;

    @ApiOperation("查询车机功能列表")
    @PreAuthorize("@ss.hasPermi('ti:function:list')")
    @GetMapping("/list")
    public TableDataInfo list(TiVehicleFunctionVO tiVehicleFunctionVO) {
        startPage();
        List<TiVehicleFunction> list = tiVehicleFunctionService.selectTiVehicleFunctionList(tiVehicleFunctionVO);
        return getDataTable(list);
    }

    @ApiOperation("获取车机功能详细信息")
    @PreAuthorize("@ss.hasPermi('ti:function:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tiVehicleFunctionService.selectTiVehicleFunctionById(id));
    }


    @ApiOperation("获取车机功能详细信息帶字典")
    @PreAuthorize("@ss.hasPermi('ti:function:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult getDetailInfo(@PathVariable("id") Long id) {
        return success(tiVehicleFunctionService.selectTiVehicleFunctionDetailById(id));
    }

    @ApiOperation("新增车机功能")
    @PreAuthorize("@ss.hasPermi('ti:function:add')")
    @Log(title = "车机功能", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TiVehicleFunction tiVehicleConfig) {
        return toAjax(tiVehicleFunctionService.insertTiVehicleFunction(tiVehicleConfig));
    }

    @ApiOperation("修改车机功能")
    @PreAuthorize("@ss.hasPermi('ti:function:edit')")
    @Log(title = "车机功能", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TiVehicleFunction tiVehicleConfig) {
        return toAjax(tiVehicleFunctionService.updateTiVehicleFunction(tiVehicleConfig));
    }

    @ApiOperation("删除车机功能")
    @PreAuthorize("@ss.hasPermi('ti:function:remove')")
    @Log(title = "车机功能", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tiVehicleFunctionService.deleteTiVehicleFunctionByIds(ids));
    }
}
