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

import cn.axzo.msg.center.service.template.request.MessageTemplateSyncQueryRequest;
import cn.axzo.msg.center.service.template.request.MessageTemplateV3CreateRequest;
import cn.axzo.msg.center.service.template.request.MessageTemplateV3DeleteRequest;
import cn.axzo.msg.center.service.template.request.MessageTemplateV3PageRequest;
import cn.axzo.msg.center.service.template.request.MessageTemplateV3SyncRequest;
import cn.axzo.msg.center.service.template.request.MessageTemplateV3SyncResponse;
import cn.axzo.msg.center.service.template.request.MessageTemplateV3UpdateRequest;
import cn.axzo.msg.center.service.template.request.MessageTemplateV3UpdateStatusRequest;
import cn.axzo.msg.center.service.template.response.MessageDetailStyle;
import cn.axzo.msg.center.service.template.response.MessageTemplateV3ConfigStateResponse;
import cn.axzo.msg.center.service.template.response.MessageTemplateV3DetailResponse;
import cn.axzo.msg.center.service.template.response.MessageTemplateV3PageResponse;
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.GetMapping;
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.Collection;
import java.util.List;

/**
 * 消息模板管理
 */
@Component
@FeignClient(value = "msg-center", url = "${server.serviceUrl:http://msg-center:8080}")
public interface MessageTemplateV3Client {

    /**
     * 添加消息模板
     *
     * @param request 模板数据模型
     * @return 模板编码
     */
    @PostMapping(value = "/message/template/v3/add", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<String> save(@RequestBody @Valid MessageTemplateV3CreateRequest request);

    /**
     * 编辑消息模板
     *
     * @param request 模板数据模型
     */
    @PostMapping(value = "/message/template/v3/update", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Void> update(@RequestBody @Valid MessageTemplateV3UpdateRequest request);

    /**
     * 编辑消息模板
     *
     * @param request 模板数据模型
     */
    @PostMapping(value = "/message/template/v3/delete", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Void> delete(@RequestBody @Valid MessageTemplateV3DeleteRequest request);

    /**
     * 消息模板详情
     *
     * @param templateCode 消息模板编码
     * @return 消息模板详情
     */
    @PostMapping(value = "/message/template/v3/detail", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<MessageTemplateV3DetailResponse> detail(@RequestParam("templateCode") String templateCode);

    /**
     * 分页查询模板
     *
     * @param request 分页查询参数
     * @return 模板列表
     */
    @PostMapping(value = "/message/template/v3/page", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Page<MessageTemplateV3PageResponse>> page(@RequestBody MessageTemplateV3PageRequest request);

    /**
     * 通过模板编码查询对应的模板
     *
     * @param templateCodes  模板编码集合
     * @return 模板列表
     */
    @PostMapping(value = "/message/template/v3/list", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<List<MessageTemplateV3PageResponse>> listByCodes(@RequestParam("templateCodes") Collection<String> templateCodes);

    /**
     * 启用/禁用消息模板
     *
     * @param request 模板状态
     */
    @PostMapping(value = "/message/template/v3/update-status", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<Void> updateStatus(@RequestBody @Valid MessageTemplateV3UpdateStatusRequest request);

    /**
     * 查询消息模板
     */
    @PostMapping(value = "/message/template/v3/sync/get", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<MessageTemplateV3SyncResponse> getSyncMessageTemplate(@RequestBody @Valid MessageTemplateSyncQueryRequest request);

    /**
     * 同步消息模板
     * req-1896 说明：仅pre环境能同步
     */
    @PostMapping(value = "/message/template/v3/sync", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<String> syncTemplate(@RequestBody @Valid MessageTemplateV3SyncRequest request);

    /**
     * 获取所有消息样式
     */
    @GetMapping(value = "/message/template/v3/list-template-detail-styles", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<List<MessageDetailStyle>> listTemplateDetailStyles();

    /**
     * 配置状态戳
     */
    @PostMapping(value = "/message/template/config/state", produces = {MediaType.APPLICATION_JSON_VALUE})
    CommonResponse<List<MessageTemplateV3ConfigStateResponse>> configState();

}
