import {
  TELEMETRY_FIELD_REGISTRY_SCHEMA_VERSION,
} from "../../../src/telemetry-field-registry.mjs";
import {
  GELIOS_PROVIDER_PACKAGE_ID,
  GELIOS_PROVIDER_PACKAGE_VERSION,
} from "./package.mjs";
import {
  GELIOS_POSITIONS_DATA_PRODUCT_ID,
} from "../v7/package.mjs";

const value = {
  schemaVersion: TELEMETRY_FIELD_REGISTRY_SCHEMA_VERSION,
  id: "gelios.units.current.telemetry.v1",
  version: "1.0.0",
  providerPackage: {
    id: GELIOS_PROVIDER_PACKAGE_ID,
    version: GELIOS_PROVIDER_PACKAGE_VERSION,
  },
  dataProductId: GELIOS_POSITIONS_DATA_PRODUCT_ID,
  sourceNamespace: "gelios.units.configured_sensor_parameter",
  entries: [
    {
      id: "gelios.sensor-parameter.in0",
      sourceKey: "in0",
      status: "approved",
      sensitivity: "operational",
      valueType: "number",
      semanticReading: {
        id: "sensor.param.in0",
        labelSource: "provider_configured",
        unitSource: "provider_configured",
      },
      allowedSurfaces: ["audit", "data_product", "analytics", "foundry"],
    },
    {
      id: "gelios.sensor-parameter.in1",
      sourceKey: "in1",
      status: "approved",
      sensitivity: "operational",
      valueType: "number",
      semanticReading: {
        id: "sensor.param.in1",
        labelSource: "provider_configured",
        unitSource: "provider_configured",
      },
      allowedSurfaces: ["audit", "data_product", "analytics", "foundry"],
    },
    {
      id: "gelios.sensor-parameter.in-underscore-0",
      sourceKey: "in_0",
      status: "observed",
      sensitivity: "unclassified",
      valueType: "unknown",
      allowedSurfaces: ["audit"],
    },
    {
      id: "gelios.sensor-parameter.in-underscore-1",
      sourceKey: "in_1",
      status: "observed",
      sensitivity: "unclassified",
      valueType: "unknown",
      allowedSurfaces: ["audit"],
    },
  ],
};

export const geliosTelemetryFieldRegistryV1 = 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;
}
