/**
 * Permissions Query Hooks
 *
 * React Query hooks for fetching permission data.
 */

import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { queryKeys } from '../../lib/queryClient';

interface Permission {
  id: string;
  name: string;
}

interface PermissionListResponse {
  rows: Permission[];
  count: number;
}

/**
 * Fetch list of permissions
 */
export function usePermissionsQuery() {
  return useQuery({
    queryKey: queryKeys.permissions.list(),
    queryFn: async (): Promise<Permission[]> => {
      const response = await axios.get<PermissionListResponse>('permissions');
      return response.data.rows;
    },
    staleTime: 30 * 60 * 1000, // Permissions rarely change
  });
}

export default usePermissionsQuery;
