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

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

/**
 * @name isCompanyAdmin
 * @description Check if the current user is a super admin.
 * @param client
 */
export async function isCompanyAdmin(client: SupabaseClient<Database>, accountSlug: string) {
  try {
    const { data, error } = await client.rpc('is_company_admin', {
      account_slug: accountSlug,
    });

    if (error) {
      throw error;
    }

    return data;
  } catch {
    return false;
  }
}
