import {TMGRoom} from './TMGRoom';
import {ITMG_ROOM_TYPE} from './TMGType';

export class TMGRoomImpl implements TMGRoom {
  private room: TMGRoomBindings|undefined;

  constructor(contextBindings: TMGContextBindings) {
    this.room = new TMGRoomBindings(contextBindings);
  }

  GetRoomID(): string {
    return this.room.getRoomID();
  }

  ChangeRoomType(roomType: ITMG_ROOM_TYPE): number {
    return this.room.changeRoomType(roomType);
  }

  GetRoomType(): number {
    return this.room.getRoomType();
  }

  StartRoomSharing(targetRoomID: string, targetUserID: string, userSig: string): number {
    return this.room.startRoomSharing(targetRoomID, targetUserID, userSig, userSig.length);
  }

  StopRoomSharing(): number {
    return this.room.stopRoomSharing();
  }

  SwitchRoom(targetRoomID: string, userSig: string): number {
    return this.room.switchRoom(targetRoomID, userSig);
  }

  SendCustomData(data: ArrayBuffer, repeatCount: number): number {
    const uint8Array = new Uint8Array(data);
    return this.room.sendCustomData(uint8Array, uint8Array.length, repeatCount);
  }

  StopSendCustomData(): number {
    return this.room.stopSendCustomData();
  }

  UpdateAudioRecvRange(range: number): number {
    return this.room.updateAudioRecvRange(range);
  }

  UpdateSpatializerRecvRange(range: number): number {
    return this.room.updateSpatializerRecvRange(range);
  }

  UpdateSelfPosition(
      position: number[], axisForward: number[], axisRight: number[], axisUp: number[]): number {
    return this.room.updateSelfPosition(
        position, position.length, axisForward, axisForward.length, axisRight, axisRight.length,
        axisUp, axisUp.length);
  }

  UpdateOtherPosition(userID: string, position: number[]): number {
    return this.room.updateOtherPosition(userID, position, position.length);
  }

  SendSEIMsg(message: string, repeatCount: number): number {
    const encoder = new TextEncoder();
    const utf8Message = encoder.encode(message);
    return this.room.sendSEIMsg(utf8Message, utf8Message.length, repeatCount);
  }
}
