/**
 * Platform Hooks
 * React Query hooks for platform-level operations
 */

import { useQuery } from '@tanstack/react-query';
import { getBusinesses, getUsers, getBusinessUsers } from '../api/platform';

/**
 * Hook to get all businesses (platform admin only)
 */
export const useBusinesses = () => {
  return useQuery({
    queryKey: ['platform', 'businesses'],
    queryFn: getBusinesses,
    staleTime: 5 * 60 * 1000, // 5 minutes
  });
};

/**
 * Hook to get all users (platform admin only)
 */
export const usePlatformUsers = () => {
  return useQuery({
    queryKey: ['platform', 'users'],
    queryFn: getUsers,
    staleTime: 5 * 60 * 1000, // 5 minutes
  });
};

/**
 * Hook to get users for a specific business
 */
export const useBusinessUsers = (businessId: number | null) => {
  return useQuery({
    queryKey: ['platform', 'business-users', businessId],
    queryFn: () => getBusinessUsers(businessId!),
    enabled: !!businessId,
    staleTime: 5 * 60 * 1000, // 5 minutes
  });
};
