var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import { TUIConferenceListManagerEvents } from "@tencentcloud/tuiroom-engine-js";
export * from "@tencentcloud/tuiroom-engine-js";
import { EventType } from "../types.mjs";
import mitt from "mitt";
class ScheduleConferenceManager {
  constructor(service) {
    __publicField(this, "service");
    __publicField(this, "customFriendList");
    __publicField(this, "emitter", mitt());
    this.service = service;
    this.bindEventContext();
    this.service.on(EventType.SERVICE_READY, () => {
      this.bindEvent();
    });
  }
  dispose() {
    this.unbindEvent();
  }
  on(eventType, callback) {
    this.emitter.on(eventType, callback);
  }
  off(eventType, callback) {
    this.emitter.off(eventType, callback);
  }
  emit(eventType, data) {
    this.emitter.emit(eventType, data);
  }
  bindEventContext() {
    this.onConferenceScheduled = this.onConferenceScheduled.bind(this);
    this.onConferenceWillStart = this.onConferenceWillStart.bind(this);
    this.onConferenceCancelled = this.onConferenceCancelled.bind(this);
    this.onConferenceInfoChanged = this.onConferenceInfoChanged.bind(this);
    this.onScheduleAttendeesChanged = this.onScheduleAttendeesChanged.bind(this);
    this.onConferenceStatusChanged = this.onConferenceStatusChanged.bind(this);
  }
  bindEvent() {
    var _a;
    const conferenceListManager = (_a = this.service.roomEngine) == null ? void 0 : _a.instance.getConferenceListManager();
    conferenceListManager.on(
      TUIConferenceListManagerEvents.onConferenceScheduled,
      this.onConferenceScheduled
    );
    conferenceListManager.on(
      TUIConferenceListManagerEvents.onConferenceWillStart,
      this.onConferenceWillStart
    );
    conferenceListManager.on(
      TUIConferenceListManagerEvents.onConferenceCancelled,
      this.onConferenceCancelled
    );
    conferenceListManager.on(
      TUIConferenceListManagerEvents.onConferenceInfoChanged,
      this.onConferenceInfoChanged
    );
    conferenceListManager.on(
      TUIConferenceListManagerEvents.onScheduleAttendeesChanged,
      this.onScheduleAttendeesChanged
    );
    conferenceListManager.on(
      TUIConferenceListManagerEvents.onConferenceStatusChanged,
      this.onConferenceStatusChanged
    );
  }
  unbindEvent() {
    var _a;
    const conferenceListManager = (_a = this.service.roomEngine) == null ? void 0 : _a.instance.getConferenceListManager();
    conferenceListManager.off(
      TUIConferenceListManagerEvents.onConferenceScheduled,
      this.onConferenceScheduled
    );
    conferenceListManager.off(
      TUIConferenceListManagerEvents.onConferenceWillStart,
      this.onConferenceWillStart
    );
    conferenceListManager.off(
      TUIConferenceListManagerEvents.onConferenceCancelled,
      this.onConferenceCancelled
    );
    conferenceListManager.off(
      TUIConferenceListManagerEvents.onConferenceInfoChanged,
      this.onConferenceInfoChanged
    );
    conferenceListManager.off(
      TUIConferenceListManagerEvents.onScheduleAttendeesChanged,
      this.onScheduleAttendeesChanged
    );
    conferenceListManager.off(
      TUIConferenceListManagerEvents.onConferenceStatusChanged,
      this.onConferenceStatusChanged
    );
  }
  onConferenceScheduled(data) {
    this.emit(TUIConferenceListManagerEvents.onConferenceScheduled, data);
  }
  onConferenceWillStart(data) {
    this.emit(TUIConferenceListManagerEvents.onConferenceWillStart, data);
  }
  onConferenceCancelled(data) {
    this.emit(TUIConferenceListManagerEvents.onConferenceCancelled, data);
  }
  onConferenceInfoChanged(data) {
    this.emit(TUIConferenceListManagerEvents.onConferenceInfoChanged, data);
    const { roomId, roomName } = data.conferenceModifyInfo.basicRoomInfo;
    const isCurrentRoom = this.service.basicStore.roomId === roomId;
    if (!isCurrentRoom) return;
    roomName !== void 0 && roomName !== null && this.service.roomStore.setRoomInfo({
      roomName
    });
  }
  onScheduleAttendeesChanged(data) {
    this.emit(TUIConferenceListManagerEvents.onScheduleAttendeesChanged, data);
  }
  onConferenceStatusChanged(data) {
    this.emit(TUIConferenceListManagerEvents.onConferenceStatusChanged, data);
  }
  async fetchFriendList() {
    var _a;
    if (this.customFriendList) return this.customFriendList;
    const tim = (_a = this.service.roomEngine.instance) == null ? void 0 : _a.getTIM();
    const { data } = await tim.getFriendList();
    return data;
  }
  replaceFriendList(userList) {
    this.customFriendList = userList;
  }
  async scheduleConference(options) {
    var _a;
    return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().scheduleConference(options));
  }
  async cancelConference(options) {
    var _a;
    return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().cancelConference(options));
  }
  async updateConferenceInfo(options) {
    var _a;
    return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().updateConferenceInfo(options));
  }
  async fetchScheduledConferenceList(options) {
    var _a;
    return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().fetchScheduledConferenceList(options));
  }
  async fetchAttendeeList(options) {
    var _a;
    return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().fetchAttendeeList(options));
  }
  async addAttendeesByAdmin(options) {
    var _a;
    return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().addAttendeesByAdmin(options));
  }
  async removeAttendeesByAdmin(options) {
    var _a;
    return await ((_a = this.service.roomEngine.instance) == null ? void 0 : _a.getConferenceListManager().removeAttendeesByAdmin(options));
  }
}
export {
  ScheduleConferenceManager
};
