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

// Kapselt /api/value-lists von omsorgCore (ValueListsController) über den generierten
// Client (omsorgcore-client-ts) - konfigurierbare Auswahllisten (Mitarbeiterstatus,
// Beschäftigungsart, CRM-Status, Einrichtungstyp, Vertragstyp/-status, Auftragsstatus).
export async function listValueLists(accessToken) {
  const api = new ValueListsApi(configFor(accessToken));
  return callApi(api.apiValueListsGetRaw());
}

export async function listItems(accessToken, key) {
  const api = new ValueListsApi(configFor(accessToken));
  return callApi(api.apiValueListsKeyItemsGetRaw({ key }));
}

export async function createItem(accessToken, key, payload) {
  const api = new ValueListsApi(configFor(accessToken));
  return callApi(api.apiValueListsKeyItemsPostRaw({ key, createValueListItemRequest: payload }));
}

export async function updateItem(accessToken, key, id, payload) {
  const api = new ValueListsApi(configFor(accessToken));
  return callApi(api.apiValueListsKeyItemsIdPutRaw({ key, id, updateValueListItemRequest: payload }));
}

export async function deleteItem(accessToken, key, id) {
  const api = new ValueListsApi(configFor(accessToken));
  return callApi(api.apiValueListsKeyItemsIdDeleteRaw({ key, id }));
}

export async function getUsages(accessToken, key, id) {
  const api = new ValueListsApi(configFor(accessToken));
  return callApi(api.apiValueListsKeyItemsIdUsagesGetRaw({ key, id }));
}

export async function listTransitions(accessToken, key) {
  const api = new ValueListsApi(configFor(accessToken));
  return callApi(api.apiValueListsKeyTransitionsGetRaw({ key }));
}

export async function replaceTransitions(accessToken, key, payload) {
  const api = new ValueListsApi(configFor(accessToken));
  return callApi(api.apiValueListsKeyTransitionsPutRaw({ key, valueListTransitionRequest: payload }));
}
