package com.yuchen.saas.park.service.controller.client;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.thinkunion.park.service.common.iot.capability.devicemodel.DeviceModel;
import com.yuchen.saas.park.api.vo.responsevo.ResponseVo;
import com.yuchen.saas.park.service.iot.IotClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

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

/**
 * iot数据获取接口
 * @author 刘通
 * @date 2020/12/25 23:45
 */
@RestController
@AllArgsConstructor
@RequestMapping("/iotClient")
@Api(value = "iot", tags = "iot")
public class IotClientController {
    @Resource
    private IotClientService iotClientService;

    /**
     * 查询所有产品
     * @return
     */
    @GetMapping("/findAllProducts")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "查询所有产品", notes = "查询所有产品")
    public R<ResponseVo> findAllProducts() {
        ResponseVo responseVo = iotClientService.findAllProducts();
        return R.data(responseVo);
    }

    /**
     * 获取某个产品的物模型
     */
    @GetMapping("/getDeviceModel")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取某个产品的物模型", notes = "获取某个产品的物模型")
    public R<DeviceModel> getDeviceModel(@RequestParam("productKey") String productKey) {
        DeviceModel deviceModel = iotClientService.getDeviceModel(productKey);
        return R.data(deviceModel);
    }

    /**
     * 通过productKey查询设备列表，除一个用端已添加的设备外
     * @param productKey
     * @return
     */
    @GetMapping("/getList")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "", notes = "")
    public R<ResponseVo> getList(String productKey) {
        ResponseVo pages = iotClientService.getList(productKey);
        return R.data(pages);
    }

    /**
     * 通过product key 获取其对应的设备列表
     * @param productKey
     * @return
     */
    @GetMapping("/getAllByProductKey")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "", notes = "")
    public R<ResponseVo> getAllByProductKey(String productKey) {
        ResponseVo pages = iotClientService.getAllByProductKey(productKey);
        return R.data(pages);
    }

    /**
     * 下发接口
     * @param body
     * @return
     */
    @PostMapping("/propertySet")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "", notes = "")
    public R<ResponseVo> propertySet(@RequestBody Map<String, Object> body) {
        ResponseVo pages = iotClientService.propertySet(body);
        return R.data(pages);
    }

    /**
     * 服务调用
     * @param body
     * @return
     */
    @PostMapping("/serviceCall")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "", notes = "")
    public R<ResponseVo> serviceCall(@RequestBody Map<String, Object> body) {
        ResponseVo pages = iotClientService.serviceCall(body);
        return R.data(pages);
    }
}
