import { apiClient } from '@/lib/api/client';
import type { UserOverview, UserDetail, ContributionRecord, MiningRecord, TradeOrder } from '@/types/user';
import type { PaginatedResponse, PaginationParams } from '@/types/api';

export const usersApi = {
  getList: async (params: PaginationParams & { keyword?: string }): Promise<PaginatedResponse<UserOverview>> => {
    const response = await apiClient.get('/users', { params });
    return response.data.data;
  },

  getDetail: async (accountSequence: string): Promise<UserDetail> => {
    const response = await apiClient.get(`/users/${accountSequence}`);
    return response.data.data;
  },

  getContributionRecords: async (
    accountSequence: string,
    params: PaginationParams
  ): Promise<PaginatedResponse<ContributionRecord>> => {
    const response = await apiClient.get(`/users/${accountSequence}/contributions`, { params });
    return response.data.data;
  },

  getMiningRecords: async (
    accountSequence: string,
    params: PaginationParams
  ): Promise<PaginatedResponse<MiningRecord>> => {
    const response = await apiClient.get(`/users/${accountSequence}/mining-records`, { params });
    return response.data.data;
  },

  getTradeOrders: async (
    accountSequence: string,
    params: PaginationParams
  ): Promise<PaginatedResponse<TradeOrder>> => {
    const response = await apiClient.get(`/users/${accountSequence}/orders`, { params });
    return response.data.data;
  },
};
