export interface UnifiedConversationReplyRow {
  id: string;
  account_id: string | null;
  external_id: string | null;
}

export type ReplyRoute =
  | { kind: "local" }
  | { kind: "web"; conversationId: string; integrationId: string };

export function replyRouteForConversation(conv: UnifiedConversationReplyRow): ReplyRoute {
  if (!conv.id.startsWith("web:")) return { kind: "local" };
  if (!conv.external_id) throw new Error("web-mirrored conversation is missing external_id");
  if (!conv.account_id) throw new Error("web-mirrored conversation is missing account_id/integrationId");
  return { kind: "web", conversationId: conv.external_id, integrationId: conv.account_id };
}
