import { Protocol } from "src/entities/WSProtocol";
import OutputBoardItemConfigEntity from "./OutputBoardItemConfigEntity";

export namespace CustomProtocol {
  export class Commands {
    public static get PROTOCOL_PREFIX() {
      return "_";
    }

    public static get kUnKnowCommand() {
      return Commands.PROTOCOL_PREFIX + "UnKnowCommand";
    }

    public static get kISVGetVideoWallConfig() {
      return Commands.PROTOCOL_PREFIX + "ISVGetVideoWallConfig";
    }
    public static get kISVSetVideoWallConfig() {
      return Commands.PROTOCOL_PREFIX + "ISVSetVideoWallConfig";
    }

    static _all_commands = new Set([
      Commands.kUnKnowCommand,
      Commands.kISVGetVideoWallConfig,
      Commands.kISVSetVideoWallConfig,
    ]);

    public static get AllCommands() {
      return this._all_commands;
    }
  }

  export class ISVGetVideoWallConfigRequestEntity extends Protocol.PacketEntity {
    timestamp = Date.now();
    constructor(rpcid?: number) {
      super();
      this.rpc_id = rpcid ?? 0;
      this.command = Commands.kISVGetVideoWallConfig;
    }
  }

  export class ISVGetVideoWallConfigResponseEntity extends Protocol.PacketEntity {
    outputs: OutputBoardItemConfigEntity[] = [];
    wall_rows = 2;
    wall_cols = 2;
    device_rotation = 0;

    constructor() {
      super();
      super.flag = Protocol.PacketEntity.FLAG_RESPONSE;
      this.command = Commands.kISVGetVideoWallConfig;
    }
  }

  export class ISVSetVideoWallConfigRequestEntity extends Protocol.PacketEntity {
    rotation_180_outputs: number[] = [];
    wall_rows = 2;
    wall_cols = 2;
    device_rotation = 0;
    constructor(
      rotation_180_outputs: number[],
      wall_rows: number,
      wall_cols: number,
      device_rotation: number,
      rpcid?: number
    ) {
      super();
      this.rpc_id = rpcid ?? 0;
      this.command = Commands.kISVSetVideoWallConfig;
      this.rotation_180_outputs = Array.isArray(rotation_180_outputs)
        ? rotation_180_outputs
        : [];
      this.wall_cols = wall_cols;
      this.wall_rows = wall_rows;
      this.device_rotation = device_rotation;
    }
  }

  export class ISVSetVideoWallConfigResponseEntity extends Protocol.PacketEntity {
    success = false;

    constructor() {
      super();
      super.flag = Protocol.PacketEntity.FLAG_RESPONSE;
      this.command = Commands.kISVSetVideoWallConfig;
    }
  }
}
