package com.sonic.pigeon.controller.api;

import com.google.common.collect.Lists;
import com.sonic.common.rpc.Result;
import com.sonic.pigeon.domain.input.SendMessageInput;
import com.sonic.pigeon.service.MessageService;
import com.sonic.sdk.api.annotation.IgnoreAuth;
import io.swagger.annotations.ApiOperation;
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;

/**
 * API-消息通知
 * @author mzc
 */
@Validated
@RestController
public class MessageApi {

    @Autowired
    private MessageService messageService;

    @IgnoreAuth
    @ApiOperation(value = "发送IM消息且不进行消息推送", tags = {"API-站内消息"})
    @RequestMapping(value = "api/message/send-message", produces = {"application/json"}, method = RequestMethod.POST)
    public Result sendMessage(@Validated @RequestBody SendMessageInput input) throws Exception {
        messageService.sendMessage(Lists.newArrayList(input));
        return Result.success();
    }

    @IgnoreAuth
    @ApiOperation(value = "发送IM消息且不进行消息推送", tags = {"API-站内消息"})
    @RequestMapping(value = "api/message/batch-send-message", produces = {"application/json"}, method = RequestMethod.POST)
    public Result sendMessage(@Validated @RequestBody List<SendMessageInput> req) throws Exception {
        messageService.sendMessage(req);
        return Result.success();
    }
}
