import type { AppSupabaseClient } from '../supabase/client.js';

export * from './attachments.js';
export * from './conversations.js';
export * from './convKeys.js';
export * from './groups.js';
export * from './messages.js';
export * from './types.js';

// ----- RPC wrappers ---------------------------------------------------------

export async function createDm(
  client: AppSupabaseClient,
  targetUserId: string,
): Promise<string> {
  const { data, error } = await client.rpc('create_dm', { target_user_id: targetUserId });
  if (error) throw error;
  if (typeof data !== 'string') throw new Error('create_dm returned non-uuid');
  return data;
}

export async function acceptDm(
  client: AppSupabaseClient,
  conversationId: string,
): Promise<void> {
  const { error } = await client.rpc('accept_dm', { conversation_id: conversationId });
  if (error) throw error;
}
