package com.fuyuanshen.app.controller;

import com.fuyuanshen.app.domain.dto.APPReNameDTO;
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
import com.fuyuanshen.web.service.device.DeviceBizService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * APP设备信息管理
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/device")
public class AppDeviceController extends BaseController {

    private final DeviceBizService appDeviceService;


    /**
     * 查询设备列表
     */
    @GetMapping("/list")
    public TableDataInfo<AppDeviceVo> list(DeviceQueryCriteria bo, PageQuery pageQuery) {
        return appDeviceService.queryAppDeviceList(bo,pageQuery);
    }

    /**
     * 绑定设备
     */
    @PostMapping("/bind")
    public R<Void> bind(@RequestBody AppDeviceBo bo) {
        return toAjax(appDeviceService.bindDevice(bo));
    }


    /**
     * 解绑设备
     */
    @DeleteMapping("/unBind")
    public R<Void> unBind(Long id) {
        Long userId = AppLoginHelper.getUserId();
        return toAjax(appDeviceService.unBindDevice(id,userId,0));
    }

    /**
     * 查询设备类型列表
     */
    @GetMapping(value = "/typeList")
    public R<List<APPDeviceTypeVo>> getTypeList() {
        List<APPDeviceTypeVo> typeList = appDeviceService.getTypeList();
        return R.ok(typeList);
    }

    /**
     * 重命名设备
     * @param reNameDTO
     * @return
     */
    @PostMapping(value = "/reName")
    public R<String> reName(@Validated @RequestBody APPReNameDTO reNameDTO) {
        appDeviceService.reName(reNameDTO);
        return R.ok("重命名成功！！！");
    }


    @GetMapping("/realTimeStatus")
    public R<Map<String, Object>> getRealTimeStatus(AppRealTimeStatusDto statusDto) {
        Map<String, Object> status = appDeviceService.getRealTimeStatus(statusDto);
        return R.ok(status);
    }

    /**
     * 根据mac查询设备信息
     */
    @GetMapping("/getDeviceInfoByDeviceMac")
    public R<AppDeviceVo> getDeviceInfo(String deviceMac) {
        return R.ok(appDeviceService.getDeviceInfo(deviceMac));
    }

}
