// lib/process/seeds/hail-engagement-lifecycle.js — shim around the JSON spec.
//
// Mirrors adgm-entity-setup.js. The authoritative spec lives in
// specs/hail-engagement-lifecycle.json. upsertDefinition validates the spec
// against the known agent templates, so seedHailAgentTemplates() MUST run first
// (lib/seeds.js enforces this order).

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 HAIL_ENGAGEMENT_LIFECYCLE_SLUG = 'hail-engagement-lifecycle';

function loadSpec() {
  const path = join(__dirname, 'specs', 'hail-engagement-lifecycle.json');
  return JSON.parse(readFileSync(path, 'utf8'));
}

let _cachedSpec = null;
export function getHailLifecycleSpec() {
  if (!_cachedSpec) _cachedSpec = loadSpec();
  return _cachedSpec;
}

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