package com.zhongshu.card.server.core.controller.mqtt;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.client.model.mqtt.MqttConfigModel;
import com.zhongshu.card.client.model.mqtt.SendMessageModel;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.server.core.service.mqtt.MqttServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 */
@RequestMapping("/mqttMessage")
@RestController
@Validated
@Tag(name = "mqtt服务")
public class MqttController {

    @Autowired
    MqttServiceImpl mqttService;

    @Operation(summary = "得到mqtt连接配置")
    @ResourceAuth(value = "user", type = AuthType.User)
    @RequestMapping(value = "getMqttConfig", method = {RequestMethod.GET})
    public ResultContent<List<MqttConfigModel>> getMqttConfig() {
        return mqttService.getMqttConfig();
    }

    @Operation(summary = "发送指令")
    @RequestMapping(value = "sendMessage", method = {RequestMethod.POST})
    public ResultContent sendMessage(@RequestBody SendMessageModel param) {
        return mqttService.sendMessage(param);
    }

}

