import type { AxiosInstance } from 'axios';
import type { CountryDTO } from '@effigenix/types';

export type { CountryDTO };

export function createCountriesResource(client: AxiosInstance) {
  return {
    async search(query?: string): Promise<CountryDTO[]> {
      const res = await client.get<CountryDTO[]>('/api/countries', {
        params: query ? { q: query } : {},
      });
      return res.data;
    },
  };
}

export type CountriesResource = ReturnType<typeof createCountriesResource>;
