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.DeviceRelation;
import com.kym.service.DeviceRelationService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 设备短编号关系管理
 * </p>
 *
 * @author skyline
 * @since 2025-05-31
 */
@RestController
@RequestMapping("/device-relation")
public class DeviceRelationController extends IController {

    private final DeviceRelationService deviceRelationService;

    public DeviceRelationController(DeviceRelationService deviceRelationService) {
        this.deviceRelationService = deviceRelationService;
    }

    @SaCheckPermission("deviceRelation.add")
    @SysLog("绑定设备短编号")
    @PostMapping("add")
    public R<?> add(@RequestBody DeviceRelation deviceRelation) {
        return resp((t) -> deviceRelationService.add(deviceRelation));
    }

    @SaCheckPermission("deviceRelation.remove")
    @SysLog("删除设备短编号关系")
    @GetMapping("remove/{id}")
    public R<?> removeById(@PathVariable Long id) {
        return resp((t) -> deviceRelationService.removeById(id));
    }

    @SaCheckPermission("deviceRelation.list")
    @SysLog("查询设备短编号关系")
    @PostMapping("list")
    public R<?> listByStationId(@RequestBody Map<String, String> params) {
        return resp(() -> deviceRelationService.listByStationId(params.get("stationId")));
    }

}
