package com.kym.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.kym.common.R;
import com.kym.common.annotation.SysLog;
import com.kym.common.controller.IController;
import com.kym.entity.DeviceConfig;
import com.kym.entity.queryParams.DeviceConfigParams;
import com.kym.entity.queryParams.DeviceConfigQueryParams;
import com.kym.service.DeviceConfigService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 洗车设备参数配置表 前端控制器
 * </p>
 *
 * @author skyline
 * @since 2025-01-19
 */
@RestController
@RequestMapping("/device-config")
public class DeviceConfigController extends IController {

    private final DeviceConfigService deviceConfigService;

    public DeviceConfigController(DeviceConfigService deviceConfigService) {
        this.deviceConfigService = deviceConfigService;
    }

    /**
     * 新增设备配置
     *
     * @param deviceConfig
     * @return Res
     */
    @SaCheckPermission(value = "deviceConfig.add")
    @PostMapping("add")
    @SysLog(value = "新增设备配置")
    public R<?> add(@Valid @RequestBody DeviceConfig deviceConfig) {
        return resp((t) -> deviceConfigService.add(deviceConfig));
    }

    /**
     * 获取设备配置
     *
     * @param id
     * @return Res
     */
//    @SaCheckPermission(value = "deviceConfig.list")
    @PostMapping("/{id}")
    @SysLog(value = "获取设备配置")
    public R<?> add(@PathVariable("id") String id) {
        return resp(() -> deviceConfigService.getById(id));
    }

    /**
     * 读取远程设备配置
     *
     * @param shortId
     * @return Res
     */
//    @SaCheckPermission(value = "deviceConfig.list")
    @GetMapping("/{shortId}")
    @SysLog(value = "读取远程设备配置")
    public R<?> readDeviceConfig(@PathVariable("shortId") String shortId) {
        return resp(() -> deviceConfigService.readDeviceConfig(shortId));
    }

    /**
     * 更新设备配置
     *
     * @param deviceConfig
     * @return Res
     */
    @SaCheckPermission(value = "deviceConfig.modify")
    @PostMapping("modify")
    @SysLog(value = "更新设备配置")
    public R<?> modify(@Valid @RequestBody DeviceConfig deviceConfig) {
        return resp((t) -> deviceConfigService.modify(deviceConfig));
    }

    /**
     * 批量更新设备的配置
     *
     * @param params
     * @return Res
     */
//    @SaCheckPermission(value = "deviceConfig.modify")
    @PostMapping("batchModify")
    @SysLog(value = "批量更新设备配置")
    public R<?> batchModify(@Valid @RequestBody DeviceConfigParams params) {
        return resp((t) -> deviceConfigService.batchModify(params));
    }


    @PostMapping("list")
    @SysLog(value = "查询设备配置")
    public R<?> list(@Valid @RequestBody DeviceConfigQueryParams params) {
        return resp(() -> deviceConfigService.list(params));
    }


}
