// lib/process/seeds/adgm-entity-setup.js — shim around the JSON spec.
//
// The authoritative spec now lives in specs/adgm-entity-setup.json. This file
// exists only so existing seed wiring (lib/seeds.js → seedAdgmEntitySetup) and
// any back-compat imports of ADGM_ENTITY_SETUP_SLUG keep working.

import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import { upsertDefinition } from '../definitions.js';

const __dirname = dirname(fileURLToPath(import.meta.url));

export const ADGM_ENTITY_SETUP_SLUG = 'adgm-entity-setup';

function loadSpec() {
  const path = join(__dirname, 'specs', 'adgm-entity-setup.json');
  return JSON.parse(readFileSync(path, 'utf8'));
}

// Lazy + cached so a single re-seed doesn't re-read disk, and tests that
// mutate the spec on disk can pick up changes via a fresh module import.
let _cachedSpec = null;
export function getAdgmEntitySetupSpec() {
  if (!_cachedSpec) _cachedSpec = loadSpec();
  return _cachedSpec;
}

export function seedAdgmEntitySetup() {
  const spec = getAdgmEntitySetupSpec();
  return upsertDefinition(spec, { source_spec_json: JSON.stringify(spec) });
}

export function seedProcessDefinitions() {
  seedAdgmEntitySetup();
}
