import { geliosCapabilityCatalogV1 } from "./capability-catalog-v1.mjs";

export const geliosCapabilityCatalogV2 = deepFreeze(updateFamilies({
  ...structuredClone(geliosCapabilityCatalogV1),
  version: "2.0.0",
  authority: {
    ...geliosCapabilityCatalogV1.authority,
    checkedAt: "2026-07-22T20:32:27Z",
  },
}));

function updateFamilies(value) {
  value.dataFamilies = value.dataFamilies.map((family) => {
    if (family.id === "gelios.unit.identity") {
      return implemented(family);
    }
    if (family.id === "gelios.unit.equipment") {
      return implemented({
        ...family,
        sourcePaths: [
          "hwManufacturer.id",
          "hwManufacturer.name",
          "hwType.id",
          "hwType.name",
          "hwType.port",
          "hwType.type",
        ],
      });
    }
    if (family.id === "gelios.unit.trip_settings") {
      return implemented(family);
    }
    return family;
  });
  return value;
}

function implemented(family) {
  return {
    ...family,
    status: "implemented",
    dataProductIds: ["fleet.units.profile.current.v1"],
  };
}

function deepFreeze(input) {
  if (!input || typeof input !== "object" || Object.isFrozen(input)) return input;
  Object.freeze(input);
  for (const child of Object.values(input)) deepFreeze(child);
  return input;
}
