package cn.reghao.tnb.content.app.chat.controller;

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.content.app.chat.model.dto.message.*;
import cn.reghao.tnb.content.app.chat.service.ChatMessageService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2022-04-17 16:30:12
 */
@RestController
@RequestMapping("/api/chat/chat")
public class ChatMsgController {
    private final ChatMessageService chatMessageService;

    public ChatMsgController(ChatMessageService chatMessageService) {
        this.chatMessageService = chatMessageService;
    }

    @Operation(summary = "发送图片消息")
    @PostMapping(value = "/message/image", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageImage(@RequestBody @Validated ImageMessage imageMessage) throws Exception {
        String url = chatMessageService.putImageMessage(imageMessage);
        if (url != null) {
            return WebResult.success(url);
        }

        return WebResult.failWithMsg("not get signed url");
    }

    @Operation(summary = "heatmap")
    @GetMapping(value = "/heatmap", produces = MediaType.APPLICATION_JSON_VALUE)
    public String heatMap() {
        return WebResult.success(chatMessageService.getDateList());
    }
}
