/* SPDX-FileCopyrightText: © 2025 Hornwitser SPDX-License-Identifier: AGPL-3.0-or-later */ import type { ApiEntity } from "~/shared/types/api"; import { Info } from "~/shared/utils/luxon"; import { ClientEntity } from "~/utils/client-entity"; const typeMap: Record>> = { "user": ClientUser, "schedule-location": ClientScheduleLocation, "schedule-event": ClientScheduleEvent, "schedule-role": ClientScheduleRole, "schedule-shift": ClientScheduleShift, }; const classMap = new Map(Object.entries(typeMap).map(([k, v]) => [v, k])); export default definePayloadPlugin(() => { definePayloadReducer( "ClientMap", data => { if (!(data instanceof ClientMap)) { return; } const type = classMap.get(data.EntityClass)!; const accountStore = useAccountStore(); return { type, timezone: accountStore.activeTimezone, locale: accountStore.activeLocale, api: data.toApi(false), }; }, ); definePayloadReviver( "ClientMap", ({ type, timezone, locale, api }) => { const EntityClass = typeMap[type]; const zone = Info.normalizeZone(timezone); return ClientMap.fromApi(EntityClass, api, { zone, locale }) }, ); });