// frontend/src/api/model/user.ts
import ApiClient from "../Client";

const API_BASE_URL = "/account/users";

const userAPI = {
  /**
   * Get all users
   * @param params optional query params
   */
  async getUsers(params?: Record<string, any>) {
    return ApiClient.request("get", `${API_BASE_URL}/`, params);
  },

  /**
   * Get a single user by ID
   * @param id user ID
   */
  async getUser(id: number | string) {
    return ApiClient.request("get", `${API_BASE_URL}/${id}/`);
  },

  /**
   * Update a user by ID
   * @param id user ID
   * @param data partial user data
   */
  async updateUser(id: number | string, data: Record<string, any>) {
    return ApiClient.request("patch", `${API_BASE_URL}/${id}/`, data);
  },

  /**
   * Delete a user by ID
   * @param id user ID
   */
  async deleteUser(id: number | string) {
    return ApiClient.request("delete", `${API_BASE_URL}/${id}/`);
  },

  /**
   * Create a new user
   * @param data user data
   */
  async createUser(data: Record<string, any>) {
    return ApiClient.request("post", `${API_BASE_URL}/`, data);
  },

  /**
   * Search users by username (partial match)
   * @param params { username: string }
   */
  async searchUsers(params: Record<string, any>) {
    return ApiClient.request("get", `${API_BASE_URL}/`, params);
  },
};

export default userAPI;
