package com.willalp.web.controller.device;

import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.core.domain.entity.SysUser;
import com.willalp.common.core.page.TableDataInfo;
import com.willalp.device.service.IDeviceService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hs
 */
@Api("control模块设备设置")
@RestController
@RequestMapping("/deviceControl")
public class ControlDeviceController extends BaseController {

    @Resource
    private IDeviceService deviceService;

    @GetMapping("/bindingList")
    public TableDataInfo getDeviceBindingUsers(@RequestParam("deviceId") String deviceId) {
        startPage();
        List<SysUser> list = deviceService.getDeviceBindingUsers(deviceId);
        return getDataTable(list);
    }

    @GetMapping("/allList")
    public TableDataInfo getDeviceAllBindingUsers(@RequestParam("userType") String userType) {
        startPage();
        List<SysUser> list = deviceService.selectAllUserList(userType);
        return getDataTable(list);
    }

    @GetMapping("/binding")
    public AjaxResult bindingUser(@RequestParam("deviceId") String deviceId,
                                  @RequestParam("userId") String userId) {
        return toAjax(deviceService.bindingUser(deviceId, userId));
    }

    @GetMapping("/untie")
    public AjaxResult untieUser(@RequestParam("deviceId") String deviceId,
                                @RequestParam("userId") String userId) {
        return toAjax(deviceService.untieUser(deviceId, userId));
    }
}
