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.test.service.ex.ExTiVehicleFunctionService;
import com.cmvr.ti.model.domain.TiVehicleUi;
import com.cmvr.ti.service.ITiVehicleFunctionService;
import com.cmvr.ti.service.ITiVehicleUiService;
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/ui")
@RequiredArgsConstructor
public class TiVehicleUiController extends BaseController {
    private final ITiVehicleUiService tiVehicleUiService;

    private final ExTiVehicleFunctionService exTiVehicleFunctionService;

    @ApiOperation("查询车机功能列表")
    @PreAuthorize("@ss.hasPermi('ti:ui:list')")
    @GetMapping("/list")
    public TableDataInfo list(TiVehicleUi tiVehicleUi) {
        startPage();
        List<TiVehicleUi> list = tiVehicleUiService.selectTiVehicleUiList(tiVehicleUi);
        return getDataTable(list);
    }

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

    @ApiOperation("新增车机功能")
    @PreAuthorize("@ss.hasPermi('ti:ui:add')")
    @Log(title = "车机界面", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TiVehicleUi tiVehicleUi) {
        return toAjax(tiVehicleUiService.insertTiVehicleUi(tiVehicleUi));
    }

    @ApiOperation("修改车机功能")
    @PreAuthorize("@ss.hasPermi('ti:ui:edit')")
    @Log(title = "车机界面", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TiVehicleUi tiVehicleUi) {
        return toAjax(tiVehicleUiService.updateTiVehicleUi(tiVehicleUi));
    }

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

    @ApiOperation("搜索路径")
    @GetMapping("/findNextClickToFunction")
    public AjaxResult findNextClickToFunction(Long vehicleConfigId, String currentUi, String clickFunction) {
        return AjaxResult.success(exTiVehicleFunctionService.findNextClickToFunction(vehicleConfigId, currentUi, clickFunction));
    }
}
