package com.fastbee.iot.haiwei.controller;

import com.fastbee.common.core.domain.CommonResult;
import com.fastbee.common.utils.json.JsonUtils;
import com.fastbee.iot.haiwei.service.HaiWeiService;
import com.fastbee.iot.model.haiwei.CmdHaiWeiVo;
import com.fastbee.iot.model.haiwei.HaiWeiDeviceInfoVo;
import com.fastbee.iot.model.haiwei.HaiWeiVo;
import com.fastbee.iot.model.haiwei.dto.CmdHaiWeiDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/haiwei/device")
@Api(tags = "海为设备")
@Slf4j
public class HaiWeiController {
    @Resource
    HaiWeiService haiWeiService;


    /**
     * 获取所有海为设备
     */
    @GetMapping("/devices")
    @ApiOperation("获取所有海为设备")
    public CommonResult<List<HaiWeiVo>> getHaiWeiDevices() {
        return haiWeiService.getHaiWeiDevices();
    }

    /**
     * 获取海为设备缓存信息
     */
    @GetMapping("/cache/{deviceId}")
    @ApiOperation("获取海为设备缓存信息")
    public CommonResult<HaiWeiDeviceInfoVo> getCache(@PathVariable("deviceId") Long deviceId) {
        return haiWeiService.getCache(deviceId);
    }

    /**
     * 向海为设备下发指令
     */
    @ApiOperation("向海为设备下发指令")
    @PostMapping("/cmd")
    public CommonResult<CmdHaiWeiVo> cmdDevices(@RequestBody CmdHaiWeiDto cmdHaiWeiDto) {
        log.info("向海为设备下发指令:{}", JsonUtils.toJsonString(cmdHaiWeiDto));
        return haiWeiService.cmdDevices(cmdHaiWeiDto);
    }


}
