import { SearchData } from "@/types/epc";

export async function fetchData(postcode: string): Promise<SearchData> {
  // TODO - add strict typing to the api response

  const response = await fetch(`/api/search?postcode=${postcode}`);

  if (!response.ok) {
    // This will activate the closest `error.js` Error Boundary
    throw new Error("Failed to fetch data");
  }

  return response.json();
}
