package cn.axzo.msg.center.service.general.client;

import cn.axzo.msg.center.api.request.CmsMsgQueryReq;
import cn.axzo.msg.center.api.response.MessageNewRes;
import cn.axzo.msg.center.service.general.client.fallback.GeneralMessageClientFallback;
import cn.axzo.msg.center.service.general.request.GeneralMessageOldDataStatisticRequest;
import cn.axzo.msg.center.service.general.request.GeneralMessageSendRequest;
import cn.axzo.msg.center.service.general.request.OldMsgStatWithMultiIdentifiesRequest;
import cn.axzo.msg.center.service.general.response.GeneralMessageOldDataStatisticResponse;
import cn.azxo.framework.common.model.CommonResponse;
import cn.azxo.framework.common.model.Page;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;

/**
 * 普通消息模块
 *
 * @author cold_blade
 * @date 2023/10/18
 * @version 1.0
 */
@Component
@FeignClient(value = "msg-center", url = "${server.serviceUrl:http://msg-center:8080}",
        fallback = GeneralMessageClientFallback.class)
public interface GeneralMessageClient {

    /**
     * 发送消息
     *
     * @param request 消息所需参数
     * @return 消息的唯一标识
     */
    @Deprecated
    @PostMapping(value = "/general-message/send", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Void> batchSend(@RequestBody @Valid GeneralMessageSendRequest request);

    /**
     * 统计旧消息的未读数以及最新一条消息内容
     *
     * @param request 消息所需参数
     * @return 消息未读数&最新一条消息内容
     */
    @PostMapping(value = "/general-message/old-data/statistic", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<GeneralMessageOldDataStatisticResponse> statisticOldData(
            @RequestBody @Valid GeneralMessageOldDataStatisticRequest request);

    /**
     * 统计旧消息的未读数
     *
     * @param request 消息所需参数
     * @return 消息未读数
     */
    @PostMapping(value = "/general-message/old-data/count-unread-with-identities",
            produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Integer> countOldMsgUnreadWithIdentities(
            @RequestBody @Valid OldMsgStatWithMultiIdentifiesRequest request);

    // jar兼容
    @Deprecated
    @PostMapping(value = "/general-message/old-data/count-unread",
            produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Integer> countUnreadFromOldMessage(
            @RequestBody @Valid GeneralMessageOldDataStatisticRequest request);

    /**
     * 旧消息的分页查询入口
     *
     * @param request 分页查询所需参数
     * @return 旧消息的分页列表
     */
    @PostMapping(value = "/general-message/old-data/page", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Page<MessageNewRes>> pageQueryOldMessage(@RequestBody @Valid CmsMsgQueryReq request);
}
