export type ChannelConnectionStatus =
  | "idle"
  | "connecting"
  | "connected"
  | "reconnecting"
  | "disconnected"
  | "error";

export type ChannelTransport = "websocket" | "polling" | "http" | "unknown";

export type ChannelMessage = {
  type: string;
  _request_id?: string;
  [key: string]: unknown;
};

export type ChannelErrorPayload = {
  type?: "error";
  code?: number;
  error?: string;
  message?: string;
};

export type ChannelResponse<T = unknown> = {
  type: "response";
  request_id: string;
  data: T | ChannelErrorPayload;
};

export type ChannelOutEvent = import("./schema").WsOutEvent;

export type ChannelRequestOptions = {
  timeoutMs?: number;
  fallback?: boolean;
};

export type ChannelSocketOptions = {
  url?: string;
  namespace?: string;
  path?: string;
  restBasePath?: string;
  eventName?: string;
  windowSize?: number;
  timeoutMs?: number;
  fallback?: boolean;
  autoConnect?: boolean;
};

export type ChannelSocketState = {
  status: ChannelConnectionStatus;
  transport: ChannelTransport;
  connected: boolean;
  inFlight: number;
  queued: number;
  lastError: string | null;
};

export type ChannelEventHandler = (
  event: ChannelOutEvent,
) => void;

// --- WS token auth types ---
export type WsTokenRequest = {
  device_id: string;
  client_id: string;
};

export type WsTokenResponse = {
  access_token: string;
  expires_in_secs: number;
};

