import OutputBoardItemConfigEntity from "src/entities/OutputBoardItemConfigEntity";
import { CustomProtocol } from "src/entities/WSProtocolCustom";
import ClientConnection from "./ClientConnection";

export default class ClientConnectionCustom {
  connection_: ClientConnection | null = null;

  constructor(connection: ClientConnection) {
    this.connection_ = connection;
  }

  get connection() {
    return this.connection_;
  }

  public async getVideoWallConfig() {
    if (this.connection) {
      try {
        return await this.connection.doRpc<CustomProtocol.ISVGetVideoWallConfigResponseEntity>(
          new CustomProtocol.ISVGetVideoWallConfigRequestEntity()
        );
      } catch (e) {
        console.error(e);
        return;
      }
    }
    throw "connection is nullptr!";
  }

  public async setVideoWallConfig(
    rotation_180_outputs: number[],
    wall_rows: number,
    wall_cols: number,
    device_rotation: number
  ) {
    if (this.connection) {
      try {
        return await this.connection.doRpc<CustomProtocol.ISVSetVideoWallConfigResponseEntity>(
          new CustomProtocol.ISVSetVideoWallConfigRequestEntity(
            rotation_180_outputs,
            wall_rows,
            wall_cols,
            device_rotation
          )
        );
      } catch (e) {
        console.error(e);
        return;
      }
    }
    throw "connection is nullptr!";
  }
}
