import assertUnreachable from '../../../lang/assertUnreachable';

export enum PhenixWebSocketStatus {
  Offline = 0,
  Online = 1,
  Reconnecting = 2,
  Error = 3
}

export type PhenixWebSocketStatusType = 'Offline' | 'Online' | 'Reconnecting' | 'Error';

export class PhenixWebSocketStatusMapping {
  public static convertPhenixWebSocketStatusToPhenixWebSocketStatusType(status: PhenixWebSocketStatus): PhenixWebSocketStatusType {
    switch (status) {
      case PhenixWebSocketStatus.Offline:
        return 'Offline';
      case PhenixWebSocketStatus.Online:
        return 'Online';
      case PhenixWebSocketStatus.Reconnecting:
        return 'Reconnecting';
      case PhenixWebSocketStatus.Error:
        return 'Error';

      default:
        assertUnreachable(status);
    }
  }

  public static convertPhenixWebSocketStatusTypeToPhenixWebSocketStatus(statusType: PhenixWebSocketStatusType): PhenixWebSocketStatus {
    switch (statusType) {
      case 'Offline':
        return PhenixWebSocketStatus.Offline;
      case 'Online':
        return PhenixWebSocketStatus.Online;
      case 'Reconnecting':
        return PhenixWebSocketStatus.Reconnecting;
      case 'Error':
        return PhenixWebSocketStatus.Error;

      default:
        assertUnreachable(statusType);
    }
  }
}
