import request from "../request";

const platform = sessionStorage.getItem("platform") || "classroom";
// const api = platform == "classroom" ? "/edu-app" : "/api-backend";
let api = "/api-backend";
if (platform == "classroom") {
  api = "/edu-app";
} else if (platform == "daya") {
  api = "/api-web";
}
/**
 * 即时通讯 - 群组列表
 */
export const imGroupPage = (params?: object) => {
  if (platform == "daya") {
    return request.get(api + "/imGroup/queryGroupList", {
      params,
    });
  } else {
    return request.post(api + "/imGroup/page", {
      data: params,
    });
  }
};

/**
 * 即时通讯 - 好友列表
 */
export const imUserFriendPage = (params?: object) => {
  if (platform == "daya") {
    return request.get(api + "/imGroup/queryFriendList", {
      params,
    });
  } else {
  }
  return request.post(api + "/imGroup/page", {
    data: params,
  });
};

/**
 * 即时通讯 - 转让群组
 * [课堂乐器，管乐团]
 */
export const imGroupChangeGroupOwner = (params?: object) => {
  return request.post(api + "/imGroup/changeGroupOwner", {
    data: params,
  });
};

/**
 * 即时通讯 - 群公告列表
 */
export const imGroupNoticePage = (params?: object) => {
  if (platform == "daya") {
    return request.post(api + "/imGroup/queryNoticeList", {
      data: params,
    });
  } else {
  }
  return request.post(api + "/imGroupNotice/page", {
    data: params,
  });
};

/**
 * 即时通讯 - 新增公告
 */
let imGroupNoticeSaveUrl = api + "/imGroupNotice/save";
if (platform == "daya") {
  imGroupNoticeSaveUrl = api + "/imGroupNotice/add";
}
export const imGroupNoticeSave = (params?: object) => {
  return request.post(imGroupNoticeSaveUrl, {
    data: params,
  });
};

/**
 * 即时通讯 - 修改群公告
 * [课堂乐器，管乐团，管乐迷]
 */
export const imGroupNoticeUpdate = (params?: object) => {
  return request.post(api + "/imGroupNotice/update", {
    data: params,
  });
};

/**
 * 即时通讯 - 详情
 */
let imGroupDetailUrl = api + "/imGroup/detail/";
if (platform == "daya") {
  // https://test.dayaedu.com/api-teacher/imGroup/getDetail/1664236980537458690
  imGroupDetailUrl = api + "/imGroup/getDetail/";
}
export const imGroupDetail = (params?: any) => {
  return request.get(imGroupDetailUrl + params.id);
};

/**
 * 即时通讯 - 群成员
 */

export const imGroupMemberPage = (params?: any) => {
  if (platform == "daya") {
    return request.get(api + "/imGroup/queryGroupMemberList", {
      params,
    });
  } else {
    return request.post(api + "/imGroupMember/page", {
      data: params,
    });
  }
};

/**
 * 即时通讯 - 用户详情
 */
export const imGroupMemberUserDetail = (params?: any) => {
  if (platform == "daya") {
    return request.get(api + "/imGroup/queryFriendDetail?userId=" + params.imUserId, {
      params: {},
    });
  } else {
    return request.post(api + "/imGroupMember/userDetail", {
      data: params,
    });
  }
};

/**
 * 即时通讯 - 退出群聊
 * [课堂乐器，管乐团]
 */
export const imGroupQuit = (params?: any) => {
  return request.post(api + "/imGroup/quit/" + params.id, {
    data: params,
  });
};

/**
 * 即时通讯 - 全体禁言-解除禁言
 * [课堂乐器，管乐团]
 */
export const imGroupMuteAll = (params?: any) => {
  return request.post(api + "/imGroup/muteAll", {
    data: params,
  });
};

/**
 * 即时通讯 - 批量IM新增
 * [课堂乐器，管乐团]
 */
export const imGroupMemberSaveImAll = (params?: any) => {
  return request.post(api + "/imGroupMember/saveImAll", {
    data: params,
  });
};

/**
 * 即时通讯 - 解散群聊
 * [课堂乐器，管乐团]
 */
export const imGroupDismiss = (params?: any) => {
  return request.post(api + "/imGroup/dismiss/" + params.id, {
    data: params,
  });
};
