export async function getSportsFromApi() {
  const response = await fetch("/api/sport", {
    method: "GET",
  });
  const json = await response.json();
  return json;
}

type AddSportParameters = {
  name: string;
};

export async function addSport({ name }: AddSportParameters) {
  const response = await fetch("/api/sport", {
    method: "POST",
    body: JSON.stringify({
      name: name,
    }),
    headers: {
      "Content-Type": "application/json",
    },
  });
  const json = await response.json();
  return json;
}

type EditSportParameter = {
  id: number;
  name: string;
};

export async function editSport({ id, name }: EditSportParameter) {
  const response = await fetch(`/api/sport/${id}`, {
    method: "PATCH",
    body: JSON.stringify({
      name: name,
    }),
    headers: {
      "Content-Type": "application/json",
    },
  });
  const json = await response.json();
  return json;
}

type DeleteSportParameter = {
  id: number;
};

export async function deleteSportInApi({ id }: DeleteSportParameter) {
  const response = await fetch(`/api/sport/${id}`, {
    method: "DELETE",
  });
  const json = await response.json();
  return json;
}