package cn.axzo.msg.center.api;

import cn.axzo.msg.center.api.fallback.MessageApiFallback;
import cn.axzo.msg.center.api.request.MessageModuleStatisticReq;
import cn.axzo.msg.center.api.request.MessagePageQueryReq;
import cn.axzo.msg.center.api.request.MessageReadAllReq;
import cn.axzo.msg.center.api.request.MessageStatisticReq;
import cn.axzo.msg.center.api.response.MessageDetailRes;
import cn.axzo.msg.center.api.response.MessageModuleStatisticRes;
import cn.axzo.msg.center.api.response.MessageStatisticRes;
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;
import java.util.List;

/**
 * @description
 *   消息相关API接口定义
 *
 * @author cold_blade
 * @date 2023/9/13
 * @version 1.0
 */
@Component
@FeignClient(value = "msg-center", url = "${server.serviceUrl:http://msg-center:8080}",
        fallback = MessageApiFallback.class)
public interface MessageApi {

    /**
     * 个人消息按类型统计待办/未读数量
     *
     * @param request  个人信息及消息类型
     * @return 待办/未读数量
     */
    @PostMapping(value = "/person/message/count", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<MessageStatisticRes> countPersonMessage(@RequestBody @Valid MessageStatisticReq request);

    /**
     * 个人消息按模块分组统计
     *
     * @param request  个人信息及消息类型
     * @return 待展示的统计信息
     */
    @PostMapping(value = "/person/message/module/statistic", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<List<MessageModuleStatisticRes>> statisticPersonModuleMessage(@RequestBody @Valid
                                                                                 MessageModuleStatisticReq request);

    /**
     * 将未读消息全部置为已读
     *
     * @param request  个人信息
     */
    @PostMapping(value = "/message/read-all", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Void> readAllMessages(@RequestBody @Valid MessageReadAllReq request);

    /**
     * 消息的分页查询
     *
     * @param request 分页查询相关入参
     * @return 消息的分页数据
     */
    @PostMapping(value = "/message/record/page-query", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Page<MessageDetailRes>> pageQueryMessageRecords(@RequestBody @Valid MessagePageQueryReq request);
}
