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

import cn.axzo.msg.center.api.response.MessageDetailRes;
import cn.axzo.msg.center.service.enums.TerminalTypeEnum;
import cn.axzo.msg.center.service.enums.TodoQueryType;
import cn.axzo.msg.center.service.pending.request.CompletePendingBySubCodeRequest;
import cn.axzo.msg.center.service.pending.request.CompletePendingMessageByIdRequest;
import cn.axzo.msg.center.service.pending.request.CompletePendingMessageRequest;
import cn.axzo.msg.center.service.pending.request.PendingMessageByBizCodeRequest;
import cn.axzo.msg.center.service.pending.request.PendingMessageCountUncompletedRequest;
import cn.axzo.msg.center.service.pending.request.PendingMessageFixedTemplatePageRequest;
import cn.axzo.msg.center.service.pending.request.PendingMessageIterateRequest;
import cn.axzo.msg.center.service.pending.request.PendingMessagePageRequest;
import cn.axzo.msg.center.service.pending.request.PendingMessagePushRequest;
import cn.axzo.msg.center.service.pending.request.PendingMessageQueryRequest;
import cn.axzo.msg.center.service.pending.request.PendingMessageStatisticForWorkerRequest;
import cn.axzo.msg.center.service.pending.request.PendingMessageStatisticRequest;
import cn.axzo.msg.center.service.pending.request.PersonTodoToBeDoneStatRequest;
import cn.axzo.msg.center.service.pending.request.PresetButtonPressedRequest;
import cn.axzo.msg.center.service.pending.request.RevokePendingMessageByIdRequest;
import cn.axzo.msg.center.service.pending.request.SetHideRequest;
import cn.axzo.msg.center.service.pending.request.TodoHandoverRequest;
import cn.axzo.msg.center.service.pending.request.UpdateBusinessFinalBizStateRequest;
import cn.axzo.msg.center.service.pending.request.UpdatePendingMessageByIdRequest;
import cn.axzo.msg.center.service.pending.response.AnalysisPage;
import cn.axzo.msg.center.service.pending.response.PendingMessageIterateResponse;
import cn.axzo.msg.center.service.pending.response.PendingMessageResponse;
import cn.axzo.msg.center.service.pending.response.PendingMessageSimpleDTO;
import cn.axzo.msg.center.service.pending.response.PendingMessageStatisticResponse;
import cn.axzo.msg.center.service.pending.response.PendingMessageStatisticResponseV2;
import cn.axzo.msg.center.service.pending.response.PersonTodoToBeDoneStatResponse;
import cn.axzo.msg.center.service.pending.response.PushPendingMessageDTO;
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 org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import java.util.List;

/**
 * 代办消息模块管理
 *
 * @author cold_blade
 * @version 1.0
 * @description
 * @date 2023/9/23
 */
@Component
@FeignClient(value = "msg-center", url = "${server.serviceUrl:http://msg-center:8080}")
public interface PendingMessageClient {

    /**
     * 分类统计待办的待处理状态的数量
     *
     * <p>用groupStatisticV2替代
     *
     * @param request 统计入参
     * @return 分类信息及其对应的待处理的待办数量列表
     */
    @Deprecated
    @PostMapping(value = "/pending-message/record/group/statistic", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<List<PendingMessageStatisticResponse>> groupStatistic(
            @RequestBody @Valid PendingMessageStatisticRequest request);

    /**
     * 分类统计待办的待处理状态的数量
     *
     * @param request 统计入参
     * @return 分类信息及其对应的待处理的待办数量列表
     */
    @PostMapping(value = "/pending-message/record/group/statisticV2", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<PendingMessageStatisticResponseV2> groupStatisticV2(
            @RequestBody @Valid PendingMessageStatisticRequest request);

    /**
     * 分类统计待办的待处理状态的数量, 工人定制
     *
     * @param request 统计入参
     * @return 分类信息及其对应的待处理的待办数量列表
     */
    @PostMapping(value = "/pending-message/record/group/statisticForWorker", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<PendingMessageStatisticResponseV2> groupStatisticForWorker(
            @RequestBody @Valid PendingMessageStatisticForWorkerRequest request);

    /**
     * 统计个人在某个应用终端的待处理的待办数量
     *
     * @param request 统计入参
     * @return 待处理的待办数量
     */
    @PostMapping(value = "/pending-message/record/count/uncompleted", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Integer> countUncompleted(@RequestBody PendingMessageCountUncompletedRequest request);

    /**
     * 代办列表分页查询
     *
     * @param request 分页查询相关参数
     * @return 代办列表
     */
    @PostMapping(value = "/pending-message/record/page", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<AnalysisPage<PendingMessageResponse>> pageQuery(@RequestBody @Valid PendingMessagePageRequest request);

    /**
     * 统计个人未完成的待办数量
     */
    @PostMapping(value = "/pending-message/record/personTodoToBeDoneStat", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<PersonTodoToBeDoneStatResponse> personTodoToBeDoneStat(
            @RequestBody @Valid PersonTodoToBeDoneStatRequest request);

    /**
     * 交接未完成的业务待办
     *
     * @return 交接的数量
     */
    @PostMapping(value = "/pending-message/record/handover", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Integer> handover(@RequestBody @Valid TodoHandoverRequest request);

    /**
     * 指定几种代办模型列表分页查询
     *
     * @param request 分页查询相关参数
     * @return 代办列表
     */
    @PostMapping(value = "/pending-message/getPendingMessageByAppWorker", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<List<PendingMessageResponse>> getPendingMessageByAppWorker(@RequestBody @Valid PendingMessageFixedTemplatePageRequest request);

    /**
     * 代办列表分页查询
     *
     * @param request 分页查询相关参数
     * @return 代办列表
     */
    @Deprecated
    @PostMapping(value = "/pending-message/record/compatible/page", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Page<MessageDetailRes>> compatiblePageQuery(@RequestBody @Valid PendingMessagePageRequest request);

    /**
     * 代办列表指定待办的查询
     *
     * @param request 查询相关参数
     * @return 指定待办
     */
    @PostMapping(value = "/pending-message/record/query", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<PendingMessageResponse> query(@RequestBody @Valid PendingMessageQueryRequest request);

    /**
     * 查询代办详情
     *
     * @param msgIdentityCode 消息的唯一标识
     * @param terminalType    APP终端类型
     * @return 代办详情
     */
    @PostMapping(value = "/pending-message/record/detail", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<PendingMessageResponse> detail(@RequestParam("msgIdentityCode") String msgIdentityCode,
                                                  @RequestParam("terminalType") TerminalTypeEnum terminalType,
                                                  @RequestParam(value = "queryType", required = false)
                                                  TodoQueryType queryType);

    /**
     * 根据bizCode查询待办详情
     *
     * @return
     */
    @PostMapping(value = "/pending-message/record/get-latest-todo-by-biz", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<PendingMessageResponse> getLatestTodoByBiz(
            @RequestParam(value = "templateCode", required = false) String templateCode,
            @RequestParam(value = "bizCode", required = false) String bizCode,
            @RequestParam(value = "subBizCode", required = false) String subBizCode,
            @RequestParam(value = "todoType") String todoType);

    /**
     * 发送代办
     *
     * @param request 代办核心参数
     * @return 代办唯一标识
     */
    @PostMapping(value = "/pending-message/push", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<List<PushPendingMessageDTO>> push(@RequestBody @Valid PendingMessagePushRequest request);

    /**
     * 遍历待办数据
     *
     * @param request 代办核心参数
     * @return 代办唯一标识
     */
    @PostMapping(value = "/pending-message/iterate", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Page<PendingMessageIterateResponse>> iterate(@RequestBody @Valid PendingMessageIterateRequest request);

    /**
     * 完成代办
     *
     * @param requestNo 代办唯一标识
     * @return 成功返回 {@code true} 失败返回 {@code false}
     */
    @PostMapping(value = "/pending-message/complete", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> complete(@RequestParam("requestNo") String requestNo);

    /**
     * 完成代办
     *
     * @param param
     * @return 成功返回 {@code true} 失败返回 {@code false}
     */
    @PostMapping(value = "/pending-message/complete/by-id", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> completeById(@RequestBody @Valid CompletePendingMessageByIdRequest param);

    /**
     * 撤销代办
     *
     * @param requestNo 代办唯一标识
     * @return 成功返回 {@code true} 失败返回 {@code false}
     */
    @PostMapping(value = "/pending-message/revoke", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> revoke(@RequestParam("requestNo") String requestNo);

    /**
     * 通过ID撤销代办
     *
     * @param msgId 代办唯一标识
     * @return 成功返回 {@code true} 失败返回 {@code false}
     */
    @PostMapping(value = "/pending-message/revoke/by-id", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> revokeByMsgId(@RequestParam("msgId") String msgId);

    /**
     * 通过模版编号和业务编号完成代办
     *
     * @param param
     * @return
     */
    @PostMapping(value = "/pending-message/complete/by-biz-code", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> completeByTemplateCodeBizCode(@RequestBody @Valid CompletePendingMessageRequest param);

    @PostMapping(value = "/pending-message/update-business-final-biz-state",
            produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> updateBusinessFinalBizState(@RequestBody @Valid UpdateBusinessFinalBizStateRequest param);

    /**
     * 通过模版编号和业务编号和子业务编号完成代办
     *
     * @param param
     * @return
     */
    @PostMapping(value = "/pending-message/complete/by-sub-biz-code", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> completeByTemplateCodeSubBizCode(@RequestBody @Valid CompletePendingBySubCodeRequest param);

    /**
     * 通过模版编号和业务编号和子业务编号恢复代办
     *
     * @param param
     * @return
     */
    @PostMapping(value = "/pending-message/rollback/by-sub-biz-code", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> rollbackTemplateCodeSubBizCode(@RequestBody @Valid CompletePendingBySubCodeRequest param);

    /**
     * 通过模版编号和业务编号撤销代办
     *
     * @param param
     * @return 成功返回 {@code true} 失败返回 {@code false}
     */
    @PostMapping(value = "/pending-message/revoke/by-biz-code", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> revokeByTemplateCodeBizCode(@RequestBody @Valid CompletePendingMessageRequest param);

    /**
     * 通过ID撤销代办
     *
     * @param param
     * @return 成功返回 {@code true} 失败返回 {@code false}
     */
    @PostMapping(value = "/pending-message/revokeById", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> revokeById(@RequestBody @Valid RevokePendingMessageByIdRequest param);

    /**
     * 通过ID撤销代办
     *
     * @param param
     * @return 成功返回 {@code true} 失败返回 {@code false}
     */
    @PostMapping(value = "/pending-message/update/byId", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> updateById(@RequestBody @Valid UpdatePendingMessageByIdRequest param);

    /**
     * 将待办设置为隐藏, 列表页不展示
     */
    @PostMapping(value = "/pending-message/update/setHide", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> setHide(@RequestBody @Valid SetHideRequest req);

    /**
     * 批量将待办设置为处理中
     */
    @PostMapping(value = "/pending-message/update/batchSetProcessing", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> batchSetProcessing(@RequestBody List<String> identityCodes);

    @PostMapping(value = "/pending-message/update/batchSetProcessingByBizCodes", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> batchSetProcessingByBizCodes(@RequestBody List<String> subBizCodes);

    /**
     * 通过BizCode获取最新代办
     *
     * @param pendingMessageByBizCodeRequest
     * @return 成功返回 {@code true} 失败返回 {@code false}
     */
    @PostMapping(value = "/pending-message/latest/biz-code", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<List<PendingMessageSimpleDTO>> getLatestByBizCode(@RequestBody @Valid PendingMessageByBizCodeRequest pendingMessageByBizCodeRequest);

    /**
     * 待办预设按钮点击
     */
    @PostMapping(value = "/pending-message/fire-preset-button-pressed", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> firePresetButtonPressed(@RequestBody @Valid PresetButtonPressedRequest req);

    /**
     * 待办预设按钮点击
     */
    @PostMapping(value = "/pending-message/set-copied-to-me-read", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Boolean> setCopiedToMeRead(@RequestParam("personId") Long personId,
                                              @RequestParam(value = "identityCode", defaultValue = "") String identityCode);
}