/**
 * WebSocket Protocol Constants
 * Based on RFC 6455
 */

/**
 * WebSocket opcode types
 */
export enum WebSocketOpcode {
  CONTINUATION = 0x0,
  TEXT = 0x1,
  BINARY = 0x2,
  CLOSE = 0x8,
  PING = 0x9,
  PONG = 0xa,
}

/**
 * WebSocket close codes
 */
export enum WebSocketCloseCode {
  NORMAL_CLOSURE = 1000,
  GOING_AWAY = 1001,
  PROTOCOL_ERROR = 1002,
  UNSUPPORTED_DATA = 1003,
  NO_STATUS_RECEIVED = 1005,
  ABNORMAL_CLOSURE = 1006,
  INVALID_FRAME_PAYLOAD_DATA = 1007,
  POLICY_VIOLATION = 1008,
  MESSAGE_TOO_BIG = 1009,
  MISSING_EXTENSION = 1010,
  INTERNAL_ERROR = 1011,
  SERVICE_RESTART = 1012,
  TRY_AGAIN_LATER = 1013,
  BAD_GATEWAY = 1014,
  TLS_HANDSHAKE = 1015,
}

/**
 * WebSocket protocol version
 */
export const WEBSOCKET_VERSION = 13;

/**
 * WebSocket magic string for handshake
 */
export const WEBSOCKET_MAGIC_STRING = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';

/**
 * WebSocket headers
 */
export const WEBSOCKET_HEADERS = {
  UPGRADE: 'upgrade',
  CONNECTION: 'connection',
  SEC_WEBSOCKET_KEY: 'sec-websocket-key',
  SEC_WEBSOCKET_VERSION: 'sec-websocket-version',
  SEC_WEBSOCKET_ACCEPT: 'sec-websocket-accept',
  SEC_WEBSOCKET_PROTOCOL: 'sec-websocket-protocol',
  SEC_WEBSOCKET_EXTENSIONS: 'sec-websocket-extensions',
} as const;