import { apiGet } from './client';
import type { EquipmentItem, EquipmentDetail, PaginatedEquipment, SortOption } from '../types';

export async function fetchEquipment(params: {
  search?: string;
  category?: string;
  sort?: SortOption;
  page?: number;
  page_size?: number;
}): Promise<PaginatedEquipment> {
  return apiGet<PaginatedEquipment>('/equipment', {
    search: params.search || undefined,
    category: params.category || undefined,
    sort: params.sort || 'name_asc',
    page: params.page || 1,
    page_size: params.page_size || 24,
  });
}

export async function fetchEquipmentDetail(id: number | string): Promise<EquipmentDetail> {
  return apiGet<EquipmentDetail>(`/equipment/${id}`);
}

export async function fetchCategories(): Promise<string[]> {
  return apiGet<string[]>('/equipment/categories');
}

export async function fetchEquipmentById(id: number | string): Promise<EquipmentItem> {
  return apiGet<EquipmentItem>(`/equipment/${id}`);
}
