import { createClient } from "@/lib/supabase/server";

export async function getOrCreateConversation(user1Id: string, user2Id: string) {
  const supabase = await createClient();

  // Use the database function to get or create conversation
  const { data: conversationId, error } = await supabase
    .rpc('get_or_create_conversation', {
      user1_id: user1Id,
      user2_id: user2Id
    });

  if (error) {
    throw new Error(`Failed to get or create conversation: ${error.message}`);
  }

  return conversationId as string;
}