// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT

import { getGame } from "../utils/utils";
import { DS4ActorProxy } from "./actor/proxy";

/** @type {object | undefined} */
let fallbackData = undefined;

function getFallbackData() {
  if (!fallbackData) {
    fallbackData = {};
    for (const type of getGame().system.template.Actor?.types ?? []) {
      foundry.utils.mergeObject(fallbackData, new DS4ActorProxy({ type, name: "temporary" }).system);
    }
  }
  return fallbackData;
}

export class DS4TokenDocument extends TokenDocument {
  static getTrackedAttributes(data, _path = []) {
    if (!data) {
      data = getFallbackData();
    }
    return super.getTrackedAttributes(data, _path);
  }
}
