import { useQuery } from '@tanstack/react-query';
import { usersApi, UserQueryParams, UserDto, PaginatedUsers, UserStatistics } from '../infrastructure/users.api';

// User list query
export function useUsers(params: UserQueryParams) {
  return useQuery<PaginatedUsers>({
    queryKey: ['users', 'list', params],
    queryFn: () => usersApi.listUsers(params),
  });
}

// User statistics query
export function useUserStatistics() {
  return useQuery<UserStatistics>({
    queryKey: ['users', 'statistics'],
    queryFn: () => usersApi.getStatistics(),
    refetchInterval: 60000, // Refresh every minute
  });
}

// User search query
export function useUserSearch(keyword: string, limit = 10, enabled = true) {
  return useQuery<UserDto[]>({
    queryKey: ['users', 'search', keyword, limit],
    queryFn: () => usersApi.searchUsers(keyword, limit),
    enabled: enabled && keyword.length >= 2,
  });
}

// User detail query
export function useUserDetail(id: string, enabled = true) {
  return useQuery<UserDto>({
    queryKey: ['users', 'detail', id],
    queryFn: () => usersApi.getUserDetail(id),
    enabled: enabled && !!id,
  });
}

// Re-export types
export type { UserDto, UserType, PaginatedUsers, UserStatistics, UserQueryParams } from '../infrastructure/users.api';
