/**
 * Watch Communication Types
 * Types for iPhone ↔ Watch bidirectional communication
 */

export type TimerPhase = 'PREP' | 'WORK' | 'REST' | 'COMPLETE';

export type WatchControlAction = 'play' | 'pause' | 'skip' | 'stop' | 'previous';

export interface WorkoutState {
  phase: TimerPhase;
  timeRemaining: number;
  currentRound: number;
  totalRounds: number;
  currentExercise: string;
  nextExercise?: string;
  calories: number;
  isPaused: boolean;
  isPlaying: boolean;
}

export interface WatchAvailability {
  isSupported: boolean;
  isPaired: boolean;
  isWatchAppInstalled: boolean;
  isReachable: boolean;
}

export interface WatchMessage {
  type: string;
  [key: string]: string | number | boolean | undefined;
}

export interface WatchControlMessage extends WatchMessage {
  type: 'control';
  action: WatchControlAction;
  timestamp?: number;
}

export interface WatchStateMessage extends WatchMessage {
  type: 'workoutState';
  phase: TimerPhase;
  timeRemaining: number;
  currentRound: number;
  totalRounds: number;
  currentExercise: string;
  nextExercise?: string;
  calories: number;
  isPaused: boolean;
  isPlaying: boolean;
}

export interface HeartRateMessage extends WatchMessage {
  type: 'heartRate';
  value: number;
  timestamp: number;
}

export interface WatchConnectivityStatus {
  reachable: boolean;
}

export interface WatchStateChanged {
  isPaired: boolean;
  isWatchAppInstalled: boolean;
  isReachable: boolean;
}

export type WatchEventName = 
  | 'WatchConnectivityStatus'
  | 'WatchStateChanged'
  | 'WatchControlReceived'
  | 'WatchMessageReceived';

export interface WatchBridgeModule {
  isWatchAvailable(): Promise<WatchAvailability>;
  sendWorkoutState(state: WorkoutState): void;
  sendMessage(message: WatchMessage): void;
  sendControl(action: WatchControlAction): void;
  addListener(eventName: WatchEventName, callback: (data: Record<string, unknown>) => void): void;
  removeListener(eventName: WatchEventName, callback: (data: Record<string, unknown>) => void): void;
}
