package cn.axzo.msg.center.api;

import cn.axzo.msg.center.api.fallback.InsideMessageModuleApiFallBack;
import cn.axzo.msg.center.api.request.CreateModuleReq;
import cn.axzo.msg.center.api.request.SearchModuleReq;
import cn.axzo.msg.center.api.request.SyncModuleDataReq;
import cn.axzo.msg.center.api.request.UpdateModuleReq;
import cn.axzo.msg.center.api.response.CommonPlatManagerRes;
import cn.axzo.msg.center.api.response.MessageModuleRes;
import cn.axzo.msg.center.api.response.ModuleGroupByNameResponse;
import cn.axzo.msg.center.api.response.SyncModuleDataRes;
import cn.azxo.framework.common.model.CommonResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@FeignClient(name = "msg-center", url = "${server.serviceUrl:http://msg-center:8080}", fallback = InsideMessageModuleApiFallBack.class)
@Component
public interface InsideMessageModuleApi {

    @GetMapping("modules/get/{identityType}")
    CommonResponse<Map<Long, String>> getModules(@PathVariable Integer identityType);
    @GetMapping("modules/{identityType}")
    CommonResponse<List<MessageModuleRes>> listModuleByUserType(@PathVariable Integer identityType);

    /**
     *  查询模块列表
     * @param identityType
     * @return
     */
    @GetMapping("/module/page/list")
    CommonResponse<CommonPlatManagerRes> listModules(Integer identityType);

    /**
     *  分页查询模块
     * @param req
     * @return
     */
    @PostMapping("/module/page")
    CommonResponse<CommonPlatManagerRes> pageModules(@RequestBody SearchModuleReq req);

    /**
     *  新增模块
     * @param dto
     * @return
     */
    @PostMapping("/module/add")
    CommonResponse<String> addModule(@RequestBody CreateModuleReq dto);

    /**
     *  模块更新
     * @param dto
     * @return
     */
    @PostMapping("/module/update")
    CommonResponse<String> updateModule(@RequestBody UpdateModuleReq dto);

    /**
     * 删除模块
     * @param id
     * @return
     */
    @DeleteMapping("/module/del/{id}")
    CommonResponse<Void> deleteModule(@PathVariable Long id);

    /**
     *  根据ids查询多个模块
     * @param ids
     * @return
     */
    @GetMapping("/module/findByIds")
    CommonResponse<List<SyncModuleDataRes>> findModuleByIds(@RequestParam("ids") List<Long> ids);


    /**
     *  同步数据
     * @param dtoList
     * @return
     */
    @PostMapping ("/sync/module/data")
    CommonResponse<Void> syncData(@RequestBody List<SyncModuleDataReq> dtoList);

    /**
     *  查询模块列表并分组
     *
     * @return 分组后的模块列表
     */
    @GetMapping("/module/group-by-name")
    CommonResponse<List<ModuleGroupByNameResponse>> listModulesGroupByName();
}
