import { useQuery } from '@tanstack/react-query';
import { usersApi } from '../api/users.api';
import type { PaginationParams } from '@/types/api';

export function useUsers(params: PaginationParams & { keyword?: string }) {
  return useQuery({
    queryKey: ['users', params],
    queryFn: () => usersApi.getList(params),
  });
}

export function useUserDetail(accountSequence: string) {
  return useQuery({
    queryKey: ['users', accountSequence],
    queryFn: () => usersApi.getDetail(accountSequence),
    enabled: !!accountSequence,
  });
}

export function useContributionRecords(accountSequence: string, params: PaginationParams) {
  return useQuery({
    queryKey: ['users', accountSequence, 'contributions', params],
    queryFn: () => usersApi.getContributionRecords(accountSequence, params),
    enabled: !!accountSequence,
  });
}

export function useMiningRecords(accountSequence: string, params: PaginationParams) {
  return useQuery({
    queryKey: ['users', accountSequence, 'mining-records', params],
    queryFn: () => usersApi.getMiningRecords(accountSequence, params),
    enabled: !!accountSequence,
  });
}

export function useTradeOrders(accountSequence: string, params: PaginationParams) {
  return useQuery({
    queryKey: ['users', accountSequence, 'orders', params],
    queryFn: () => usersApi.getTradeOrders(accountSequence, params),
    enabled: !!accountSequence,
  });
}
