// WebSocket message types — client to server
export type ClientMessage =
  | { type: "message.send"; text: string; clientId: string }
  | { type: "typing.start" }
  | { type: "typing.stop" }
  | { type: "presence.ping" };

// WebSocket message types — server to client
export type ServerMessage =
  | { type: "message.new"; id: string; userId: string; text: string; createdAt: string; clientId: string }
  | { type: "typing"; userId: string; isTyping: boolean }
  | { type: "presence.update"; userId: string; status: "online" | "offline" }
  | { type: "error"; code: string; message: string };

// REST API types
export interface ChatMessage {
  id: string;
  channel_id: string;
  user_id: string;
  text: string;
  created_at: string;
  updated_at: string | null;
  deleted_at: string | null;
}

export interface UnreadCount {
  channel_id: string;
  unread_count: number;
}

// Worker environment bindings
export interface Env {
  CHAT_ROOM: DurableObjectNamespace;
  SUPABASE_URL: string;
  SUPABASE_SERVICE_ROLE_KEY: string;
  JWT_SECRET: string;
}
