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

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.content.app.chat.model.dto.chat.ChatRecordDelete;
import cn.reghao.tnb.content.app.chat.model.dto.chat.ChatRecordRevoke;
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.web.bind.annotation.*;

import java.io.IOException;

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

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

    @Operation(summary = "发送文本消息")
    @PostMapping(value = "/message/text", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageText(@RequestBody TextMsg textMsg) throws IOException {
        chatMessageService.sendTextMessage(textMsg);
        return WebResult.success();
    }

    @Operation(summary = "发送表情包消息")
    @PostMapping(value = "/message/emoticon", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageEmoticon(@RequestBody EmoticonMsg emoticonMsg) {
        chatMessageService.sendEmoticonMessage(emoticonMsg);
        return WebResult.success();
    }

    @Operation(summary = "发送图片消息")
    @PostMapping(value = "/message/image", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageImage(ImageMsg imageMsg) throws IOException {
        chatMessageService.sendImageMessage(imageMsg);
        return WebResult.success();
    }

    @Operation(summary = "发送文件消息")
    @PostMapping(value = "/message/file", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageFile(@RequestBody FileMsg fileMsg) throws IOException {
        chatMessageService.sendFileMessage(fileMsg);
        return WebResult.success();
    }

    @Operation(summary = "转发聊天记录消息")
    @PostMapping(value = "/message/forward", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageForward(@RequestBody ForwardMsg forwardMsg) {
        return WebResult.success();
    }

    @Operation(summary = "发送代码块消息")
    @PostMapping(value = "/message/code", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageCode(@RequestBody CodeBlockMsg codeBlockMsg) throws IOException {
        chatMessageService.sendCodeBlockMessage(codeBlockMsg);
        return WebResult.success();
    }

    @Operation(summary = "(群组中)发送投票消息")
    @PostMapping(value = "/message/vote", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageVote(@RequestBody VoteMsg voteMsg) {
        return WebResult.success();
    }

    @Operation(summary = "(群组中)进行投票")
    @PostMapping(value = "/message/vote/handle", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageVoteHandle(@RequestParam("record_id") int recordId,
                                        @RequestParam("options") String options) {
        VoteMsgResult voteMsgResult = new VoteMsgResult();
        return WebResult.success(voteMsgResult);
    }

    @Operation(summary = "撤回消息")
    @PostMapping(value = "/message/revoke", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageRevoke(@RequestBody ChatRecordRevoke chatRecordRevoke) throws IOException {
        long recordId = chatRecordRevoke.getRecordId();
        chatMessageService.revokeChatRecord(recordId);
        return WebResult.success();
    }

    @Operation(summary = "删除消息")
    @PostMapping(value = "/message/delete", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageDelete(@RequestBody ChatRecordDelete chatRecordDelete) {
        return WebResult.success();
    }

    @Operation(summary = "收藏(表情包)消息")
    @PostMapping(value = "/message/collect", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkMessageCollect(@RequestParam("record_id") int recordId) {
        return WebResult.success();
    }
}
