// Call signaling + token types. Realtime broadcast payloads live on a
// per-user channel (`call-signals:<userId>`) so incoming invites surface
// even if the recipient isn't currently on the relevant chat route.

export type CallKind = 'audio' | 'video';

export interface CallInvitePayload {
  type: 'invite';
  callId: string;
  conversationId: string;
  fromUserId: string;
  kind: CallKind;
  sentAt: string; // ISO
}

export interface CallAcceptPayload {
  type: 'accept';
  callId: string;
  byUserId: string;
}

export interface CallRejectPayload {
  type: 'reject';
  callId: string;
  byUserId: string;
}

export interface CallCancelPayload {
  type: 'cancel';
  callId: string;
  byUserId: string;
}

export interface CallEndPayload {
  type: 'end';
  callId: string;
  byUserId: string;
}

export type CallSignal =
  | CallInvitePayload
  | CallAcceptPayload
  | CallRejectPayload
  | CallCancelPayload
  | CallEndPayload;

export function signalTopic(userId: string): string {
  return 'call-signals:' + userId;
}

export interface LivekitToken {
  token: string;
  url: string;
  roomName: string;
  identity: string;
}
