import { FacilitiesApi } from "omsorgcore-client-ts";
import { configFor, callApi } from "./apiClientHelpers.js";

// Kapselt /api/facilities von omsorgCore (FacilitiesController) über den generierten
// Client (omsorgcore-client-ts). Feldnamen sind camelCase, da ASP.NET Core
// standardmäßig camelCase-JSON ausgibt.
export async function listFacilities(accessToken, { search, crmStatus, followUpDueOnly, page = 1, pageSize = 20 } = {}) {
  const api = new FacilitiesApi(configFor(accessToken));
  return callApi(api.apiFacilitiesGetRaw({ search, crmStatus, followUpDueOnly, page, pageSize }));
}

export async function createFacility(accessToken, payload) {
  const api = new FacilitiesApi(configFor(accessToken));
  return callApi(api.apiFacilitiesPostRaw({ createFacilityRequest: payload }));
}

export async function getFacility(accessToken, id) {
  const api = new FacilitiesApi(configFor(accessToken));
  return callApi(api.apiFacilitiesIdGetRaw({ id }));
}

export async function updateFacility(accessToken, id, payload) {
  const api = new FacilitiesApi(configFor(accessToken));
  return callApi(api.apiFacilitiesIdPutRaw({ id, updateFacilityRequest: payload }));
}

export async function deleteFacility(accessToken, id) {
  const api = new FacilitiesApi(configFor(accessToken));
  return callApi(api.apiFacilitiesIdDeleteRaw({ id }));
}
