import { readFile } from 'node:fs/promises';
import ContinuumArtifactDescriptor from "../../domain/continuum/ContinuumArtifactDescriptor.js";
import ContinuumArtifactIngestionPolicy from "../../domain/continuum/ContinuumArtifactIngestionPolicy.js";
import { parseContinuumArtifactDescriptorFields } from "./continuumArtifactJsonParser.js";
import { validateLoadContext } from "./continuumArtifactJsonValidation.js";
/** Loads Continuum artifact descriptors from JSON files at the adapter edge. */
export default class ContinuumArtifactJsonFileAdapter {
    policy;
    constructor(policy = new ContinuumArtifactIngestionPolicy()) {
        this.policy = policy;
    }
    /** Reads and ingests a generated artifact descriptor from disk. */
    async loadFile(path, context) {
        const raw = await readFile(path, 'utf8');
        return this.loadString(raw, context);
    }
    /** Ingests a generated artifact descriptor from JSON text. */
    loadString(raw, context) {
        validateLoadContext(context);
        const fields = parseContinuumArtifactDescriptorFields(raw, context);
        return this.policy.ingest(new ContinuumArtifactDescriptor(fields));
    }
}
