package com.sikey.wa04.api.message.client.rest;

import com.sikey.wa04.business.application.service.message.HistoryMessageService;
import com.sikey.wa04.business.infrastructure.configuration.ProjectContextConstant;
import com.sikey.wa04.business.infrastructure.dto.request.messaging.HistoryMessageSessionRequest;
import com.sikey.wa04.business.infrastructure.dto.request.messaging.HistoryUnreadMessageRequest;
import com.sikey.wa04.business.infrastructure.dto.response.messaging.HistoryMessageSessionResponse;
import com.sikey.wa04.business.infrastructure.dto.response.messaging.HistoryUnreadMessageResponse;
import com.sikey.wa04.common.BaseController;
import com.sikey.wa04.common.interceptor.Authenticated;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 历史消息
 *
 * @author luoyangwei
 * @date 2024年10月16日11:19:02
 */
@RestController
@RequestMapping(ProjectContextConstant.MESSAGE_URL + "/history")
public class HistoryMessageController extends BaseController {

    @Resource
    private HistoryMessageService historyMessageService;

    /**
     * 加载会话消息
     *
     * @param request 请求
     * @return 响应
     */
    @Authenticated
    @GetMapping("/session")
    public HistoryMessageSessionResponse session(@Valid HistoryMessageSessionRequest request) throws Exception {
        return historyMessageService.loadSession(request);
    }

    /**
     * 加载未读消息
     *
     * @param request 请求
     * @return 响应
     * @throws Exception 异常
     */
    @Authenticated
    @GetMapping("/unread")
    public HistoryUnreadMessageResponse unread(@Valid HistoryUnreadMessageRequest request) throws Exception {
        return historyMessageService.appLoadUnread(request);
    }

}
