/**
 * TypeScript types matching guruconnect.proto definitions
 * These are used for WebSocket message handling in the viewer
 */

export enum SessionType {
  SCREEN_CONTROL = 0,
  VIEW_ONLY = 1,
  BACKSTAGE = 2,
  FILE_TRANSFER = 3,
}

export interface SessionRequest {
  agentId: string;
  sessionToken: string;
  sessionType: SessionType;
  clientVersion: string;
}

export interface SessionResponse {
  success: boolean;
  sessionId: string;
  error?: string;
  displayInfo?: DisplayInfo;
}

export interface DisplayInfo {
  displays: Display[];
  primaryDisplay: number;
}

export interface Display {
  id: number;
  name: string;
  x: number;
  y: number;
  width: number;
  height: number;
  isPrimary: boolean;
}

export interface DirtyRect {
  x: number;
  y: number;
  width: number;
  height: number;
}

export interface RawFrame {
  width: number;
  height: number;
  data: Uint8Array;
  compressed: boolean;
  dirtyRects: DirtyRect[];
  isKeyframe: boolean;
}

export interface EncodedFrame {
  data: Uint8Array;
  keyframe: boolean;
  pts: number;
  dts: number;
}

export interface VideoFrame {
  timestamp: number;
  displayId: number;
  sequence: number;
  encoding: 'raw' | 'vp9' | 'h264' | 'h265';
  raw?: RawFrame;
  encoded?: EncodedFrame;
}

export enum MouseEventType {
  MOUSE_MOVE = 0,
  MOUSE_DOWN = 1,
  MOUSE_UP = 2,
  MOUSE_WHEEL = 3,
}

export interface MouseButtons {
  left: boolean;
  right: boolean;
  middle: boolean;
  x1: boolean;
  x2: boolean;
}

export interface MouseEvent {
  x: number;
  y: number;
  buttons: MouseButtons;
  wheelDeltaX: number;
  wheelDeltaY: number;
  eventType: MouseEventType;
}

export enum KeyEventType {
  KEY_VK = 0,
  KEY_SCAN = 1,
  KEY_UNICODE = 2,
}

export interface Modifiers {
  ctrl: boolean;
  alt: boolean;
  shift: boolean;
  meta: boolean;
  capsLock: boolean;
  numLock: boolean;
}

export interface KeyEvent {
  down: boolean;
  keyType: KeyEventType;
  vkCode: number;
  scanCode: number;
  unicode?: string;
  modifiers: Modifiers;
}

export interface QualitySettings {
  preset: 'auto' | 'low' | 'balanced' | 'high';
  customFps?: number;
  customBitrate?: number;
  codec: 'auto' | 'raw' | 'vp9' | 'h264' | 'h265';
}

export interface ConnectionStatus {
  connected: boolean;
  sessionId?: string;
  latencyMs?: number;
  fps?: number;
  bitrateKbps?: number;
}
