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.ChatRecordGet;
import cn.reghao.tnb.content.app.chat.model.dto.chat.ChatRecordGetRetList;
import cn.reghao.tnb.content.app.chat.service.ChatRecordService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author reghao
 * @date 2022-04-16 20:43:30
 */
@RestController
@RequestMapping("/api/chat/v1/talk")
public class ChatRecordController {
    private final ChatRecordService chatRecordService;

    public ChatRecordController(ChatRecordService chatRecordService) {
        this.chatRecordService = chatRecordService;
    }

    @Operation(summary = "获取与联系人的聊天记录")
    @GetMapping(value = "/records", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkRecords(ChatRecordGet chatRecordGet) {
        long receiverId = chatRecordGet.getReceiverId();
        long recordId = chatRecordGet.getRecordId();
        int limit = chatRecordGet.getLimit();
        int chatType = chatRecordGet.getTalkType();
        ChatRecordGetRetList chatRecordGetRetList = chatRecordService.getChatRecords(receiverId, recordId, limit);
        return WebResult.success(chatRecordGetRetList);
    }

    @Operation(summary = "获取与联系人的历史聊天记录")
    @GetMapping(value = "/records/history", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkRecordsHistory(ChatRecordGet chatRecordGet) {
        long receiverId = chatRecordGet.getReceiverId();
        long recordId = chatRecordGet.getRecordId();
        int limit = chatRecordGet.getLimit();
        int msgType = chatRecordGet.getMsgType();

        ChatRecordGetRetList list;
        if (msgType == 0) {
            list = chatRecordService.getChatRecords(receiverId, recordId, limit);
        } else {
            list = chatRecordService.getChatRecords(msgType, receiverId, recordId, limit);
        }
        return WebResult.success(list);
    }

    @Operation(summary = "转发聊天记录")
    @GetMapping(value = "/records/forward", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkRecordsForward() {
        return WebResult.success();
    }

    @GetMapping(value = "/search-chat-records", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkSearchChatRecords() {
        return WebResult.success();
    }

    @GetMapping(value = "/get-records-context", produces = MediaType.APPLICATION_JSON_VALUE)
    public String talkGetRecordsContext() {
        return WebResult.success();
    }
}
