import { SupabaseClient } from '@supabase/supabase-js';

import { Database } from '@kit/supabase/database';

/**
 * @name isDoctor
 * @description Check if the current user is a doctor.
 * @param client
 */
export async function isDoctor(client: SupabaseClient<Database>) {
  try {
    const { data, error } = await client.schema('medreport').rpc('is_doctor');

    if (error) {
      throw error;
    }

    return data;
  } catch {
    return false;
  }
}
