import {
  geliosTelemetryFieldRegistryV1,
} from "../v8/telemetry-field-registry.mjs";
import {
  GELIOS_PROVIDER_PACKAGE_ID,
  GELIOS_PROVIDER_PACKAGE_VERSION,
} from "./package.mjs";

const value = structuredClone(geliosTelemetryFieldRegistryV1);
value.id = "gelios.units.current.telemetry.v2";
value.version = "2.0.0";
value.providerPackage = {
  id: GELIOS_PROVIDER_PACKAGE_ID,
  version: GELIOS_PROVIDER_PACKAGE_VERSION,
};
value.entries = value.entries.map((entry) => {
  if (!["in_0", "in_1"].includes(entry.sourceKey)) return entry;
  return {
    ...entry,
    status: "approved",
    sensitivity: "operational",
    valueType: "number",
    semanticReading: {
      id: `sensor.param.${entry.sourceKey}`,
      labelSource: "provider_configured",
      unitSource: "provider_configured",
    },
    allowedSurfaces: ["audit", "data_product", "analytics", "foundry"],
  };
});

export const geliosTelemetryFieldRegistryV2 = deepFreeze(value);

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;
}
