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

// Kapselt /api/facilities/{facilityId}/employee-distances von omsorgCore
// (EmployeeFacilityDistancesController) über den generierten Client (omsorgcore-client-ts).
// Mitarbeiter-Einrichtung-Entfernungen sind eine 1:n-Unterressource von Facility (FR-EIN-4,
// Grundlage für die kilometerbasierte Fahrtkostenabrechnung).
export async function listEmployeeFacilityDistances(accessToken, facilityId) {
  const api = new EmployeeFacilityDistancesApi(configFor(accessToken));
  return callApi(api.apiFacilitiesFacilityIdEmployeeDistancesGetRaw({ facilityId }));
}

export async function createEmployeeFacilityDistance(accessToken, facilityId, payload) {
  const api = new EmployeeFacilityDistancesApi(configFor(accessToken));
  return callApi(api.apiFacilitiesFacilityIdEmployeeDistancesPostRaw({ facilityId, createEmployeeFacilityDistanceRequest: payload }));
}

export async function updateEmployeeFacilityDistance(accessToken, facilityId, id, payload) {
  const api = new EmployeeFacilityDistancesApi(configFor(accessToken));
  return callApi(api.apiFacilitiesFacilityIdEmployeeDistancesIdPutRaw({ facilityId, id, updateEmployeeFacilityDistanceRequest: payload }));
}

export async function deleteEmployeeFacilityDistance(accessToken, facilityId, id) {
  const api = new EmployeeFacilityDistancesApi(configFor(accessToken));
  return callApi(api.apiFacilitiesFacilityIdEmployeeDistancesIdDeleteRaw({ facilityId, id }));
}
