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

// Kapselt /api/facilities/{facilityId}/contacts von omsorgCore (FacilityContactsController)
// über den generierten Client (omsorgcore-client-ts). Ansprechpartner sind eine
// 1:n-Unterressource von Facility, kein eigenständiger Endpunkt.
export async function listFacilityContacts(accessToken, facilityId) {
  const api = new FacilityContactsApi(configFor(accessToken));
  return callApi(api.apiFacilitiesFacilityIdContactsGetRaw({ facilityId }));
}

export async function createFacilityContact(accessToken, facilityId, payload) {
  const api = new FacilityContactsApi(configFor(accessToken));
  return callApi(api.apiFacilitiesFacilityIdContactsPostRaw({ facilityId, createFacilityContactRequest: payload }));
}

export async function updateFacilityContact(accessToken, facilityId, id, payload) {
  const api = new FacilityContactsApi(configFor(accessToken));
  return callApi(api.apiFacilitiesFacilityIdContactsIdPutRaw({ facilityId, id, updateFacilityContactRequest: payload }));
}

export async function deleteFacilityContact(accessToken, facilityId, id) {
  const api = new FacilityContactsApi(configFor(accessToken));
  return callApi(api.apiFacilitiesFacilityIdContactsIdDeleteRaw({ facilityId, id }));
}
