package com.nokia.sms.controller;

import com.nokia.common.http.R;
import com.nokia.sms.dto.SendDingTalkMessageDTO;
import com.nokia.sms.service.DingTalkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 使用联通集团能力商店发布的能力向钉钉群推送消息
 *
 */
@Slf4j
@RestController
@RequestMapping("/api/dingtalk")
public class DingTalkController {
    private final DingTalkService dingTalkService;

    public DingTalkController(DingTalkService dingTalkService) {
        this.dingTalkService = dingTalkService;
    }

    /**
     * 发送普通文本消息
     *
     * @param dto dto
     * @return {@link R}
     */
    @PostMapping("/sendTextMessage")
    public R sendTextMessage(@Valid @RequestBody SendDingTalkMessageDTO dto) {
        return dingTalkService.sendTextMessage(dto);
    }
}
