package com.ym.mec.im;

import com.ym.mec.common.config.FeignConfiguration;
import com.ym.mec.common.entity.*;
import com.ym.mec.im.entity.GroupModel;
import com.ym.mec.im.fallback.ImFeignServiceFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
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;

@FeignClient(name = "im-server", configuration = FeignConfiguration.class, fallback = ImFeignServiceFallback.class)
public interface ImFeignService {

    /**
     * 用户注册
     *
     * @param userModel
     * @return
     */
    @PostMapping(value = "user/register", consumes = MediaType.APPLICATION_JSON_VALUE)
    ImResult register(@RequestBody ImUserModel userModel);

    /**
     * 用户信息修改
     *
     * @param userModel
     * @return
     */
    @PostMapping(value = "user/update", consumes = MediaType.APPLICATION_JSON_VALUE)
    void update(@RequestBody ImUserModel userModel);

    /**
     * 创建群组
     *
     * @param groupModel
     * @return
     */
    @PostMapping(value = "group/create")
    Object groupCreate(@RequestBody GroupModel groupModel);

    /**
     * 修改群组
     *
     * @param groupModel
     * @return
     */
    @PostMapping(value = "group/update")
    Object groupUpdate(@RequestBody GroupModel groupModel);

    /**
     * 批量创建群组
     *
     * @param groupModels
     * @return
     */
    @PostMapping(value = "group/batchCreate")
    void groupBatchCreate(@RequestBody List<GroupModel> groupModels);

    /**
     * 加入群组
     *
     * @param groupModel
     * @return
     */
    @PostMapping(value = "group/join")
    Object groupJoin(@RequestBody GroupModel groupModel);

    /**
     * 批量加入群组
     *
     * @param groupModels
     * @return
     */
    @PostMapping(value = "group/batchJoin")
    Object groupBatchJoin(@RequestBody List<GroupModel> groupModels);

    /**
     * 退出群组
     *
     * @param groupModel
     * @return
     */
    @PostMapping(value = "group/quit")
    Object groupQuit(@RequestBody GroupModel groupModel);

    /**
     * 解散群组
     *
     * @param groupModel
     * @return
     */
    @PostMapping(value = "group/dismiss")
    Object groupDismiss(@RequestBody GroupModel groupModel);

    /**
     * 批量解散群组
     *
     * @param groupModels
     * @return
     */
    @PostMapping(value = "group/batchDismiss")
    Object groupBatchDismiss(@RequestBody List<ImGroupModel> groupModels);

    /**
     * 批量退出群组
     *
     * @param groupModels
     * @return
     */
    @PostMapping(value = "group/batchQuit")
    Object groupBatchQuit(@RequestBody List<GroupModel> groupModels);

    /**
     * 发送私聊消息
     *
     * @param privateMessage
     * @return
     */
    @PostMapping(value = "private/send")
    Object privateSend(@RequestBody ImMessageDto imMessageDto);

    @PostMapping(value = "group/send")
    Object groupSend(@RequestBody ImMessageDto imMessageDto);

    /**
     * 获取历史消息记录
     *
     * @param date
     * @return
     */
    @PostMapping(value = "history/get")
    Object historyGet(@RequestParam("date") String date);

    /**
     * 创建直播房间
     *
     * @param roomId   直播间uid
     * @param roomName 直播间名称
     */
    @PostMapping(value = "/liveRoom/create")
    Object createLiveRoom(@RequestParam("roomId") String roomId, @RequestParam("roomName") String roomName);

    /**
     * 销毁直播房间
     *
     * @param roomId 直播间uid
     */
    @PostMapping(value = "/liveRoom/destroy")
    Object destroyLiveRoom(@RequestParam("roomId") String roomId);

    /**
     * @param roomId
     * @return void
     * @description: 录制直播
     * @author zx
     * @date 2022/2/25 13:52
     */
    @PostMapping(value = "/liveRoom/startRecord")
    void startRecord(@RequestParam("roomId") String roomId, @RequestParam("videoResolution") String videoResolution);

    /**
     * @param roomId
     * @return void
     * @description: 结束录制直播
     * @author zx
     * @date 2022/2/25 13:52
     */
    @PostMapping(value = "/liveRoom/stopRecord")
    void stopRecord(@RequestParam("roomId") String roomId);

    /**
     * 向直播间发送文本消息
     */
    @PostMapping(value = "/liveRoom/publishRoomMsg", consumes = MediaType.APPLICATION_JSON_VALUE)
    Object publishRoomMsg(@RequestBody ImRoomMessage message);

    /**
     * 查询用户是否在聊天室
     *
     * @param chatroomId 要查询的聊天室 ID（必传）
     * @param userId     要查询的用户 ID（必传）
     * @return true 在聊天室，false 不在聊天室
     */
    @PostMapping(value = "/liveRoom/userExistInRoom")
    boolean userExistInRoom(@RequestParam("chatroomId") String chatroomId, @RequestParam("userId") String userId);

    /**
     * 查询用户是否在线
     * 注意：断网时，用户状态返回可能不准确
     *
     * @param userId 要查询的用户 ID（必传）
     * @return 在线状态，true 在线，false 不在线
     */
    @PostMapping(value = "/liveRoom/checkOnline")
    boolean checkOnline(@RequestParam("userId") String userId);

    /**
     * 添加禁言成员-默认禁言120分钟
     *
     * @param roomUid 房间uid
     * @param userId  用户id
     */
    @PostMapping(value ="/liveRoom/addUserUnableSpeak")
    boolean addUserUnableSpeak(@RequestParam("roomUid") String roomUid, @RequestParam("userId") String userId);

    /**
     * 移除禁言成员
     *
     * @param roomUid 房间uid
     * @param userId  用户id
     */
    @PostMapping(value ="/liveRoom/removeUserUnableSpeak")
    boolean removeUserUnableSpeak(@RequestParam("roomUid") String roomUid, @RequestParam("userId") String userId);

}
