import api from './api';
import type { Listing, Category, ListingDetail } from '../types';

export const publicService = {
  getLatestListings: async (): Promise<Listing[]> => {
    const response = await api.get<Listing[]>('/listings');
    return response.data;
  },

  searchListings: async (query: string): Promise<Listing[]> => {
    const response = await api.get<Listing[]>('/listings', {
      params: { q: query }
    });
    return response.data;
  },

  getListingDetail: async (id: number): Promise<ListingDetail> => {
    const response = await api.get<ListingDetail>(`/listings/${id}`);
    return response.data;
  },

  getCategories: async (): Promise<Category[]> => {
    const response = await api.get<Category[]>('/categories');
    return response.data;
  }
};