import { internal } from '../../../../_generated/api';
import type { Id } from '../../../../_generated/dataModel';
import type { ActionCtx } from '../../../../_generated/server';

/**
 * Check if a conversation exists by external message ID
 */
export async function checkConversationExists(
  ctx: ActionCtx,
  organizationId: string,
  externalMessageId: string,
): Promise<{ _id: Id<'conversations'>; metadata?: unknown } | null> {
  return (await ctx.runQuery(
    internal.conversations.internal_queries.getConversationByExternalMessageId,
    {
      organizationId,
      externalMessageId,
    },
  )) as { _id: Id<'conversations'>; metadata?: unknown } | null;
}
