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

// Kapselt /api/contracts von omsorgCore (ContractsController) über den generierten
// Client (omsorgcore-client-ts). Feldnamen sind camelCase, da ASP.NET Core
// standardmäßig camelCase-JSON ausgibt.
export async function listContracts(accessToken, { employeeId, facilityId, search, status, page = 1, pageSize = 20 } = {}) {
  const api = new ContractsApi(configFor(accessToken));
  return callApi(api.apiContractsGetRaw({ employeeId, facilityId, search, status, page, pageSize }));
}

export async function createContract(accessToken, payload) {
  const api = new ContractsApi(configFor(accessToken));
  return callApi(api.apiContractsPostRaw({ createContractRequest: payload }));
}

export async function updateContract(accessToken, id, payload) {
  const api = new ContractsApi(configFor(accessToken));
  return callApi(api.apiContractsIdPutRaw({ id, updateContractRequest: payload }));
}

export async function deleteContract(accessToken, id) {
  const api = new ContractsApi(configFor(accessToken));
  return callApi(api.apiContractsIdDeleteRaw({ id }));
}
