import { createCoreAPIClient } from "../coreClient";
import type { CoreAPIPagination } from "../types";
import type { Destination } from "./types";

const coreClient = createCoreAPIClient();

export async function searchDestinations(page = 1, search?: string) {
  const params = new URLSearchParams();
  params.set("page", page.toString());
  if (search) {
    params.set("searchToken", search);
  }

  const response = await coreClient<{
    destinations: Destination[];
    pagination: CoreAPIPagination;
  }>(`/admin/v1/destinations?${params.toString()}`);
  return response;
}

export async function searchDestination(slug: string) {
  const response = await coreClient<Destination>(
    `/admin/v1/destinations/${slug}`,
  );
  return response;
}
