import MemoryBudgetError from "../../errors/MemoryBudgetError.js";
import CheckpointFactResolver from "./CheckpointFactResolver.js";
/** Write precondition resolver for existing entities over bounded checkpoint facts. */
export default class CheckpointExistingEntityWriteResolver {
    _factResolver;
    constructor(fields) {
        const validFields = requireResolverFields(fields);
        this._factResolver = new CheckpointFactResolver({ pool: validFields.pool });
        Object.freeze(this);
    }
    async canWriteNodeProperty(facts, nodeId) {
        return await this._factResolver.resolveNodeLiveness(facts, nodeId) === true;
    }
    async canWriteEdgeProperty(facts, edge) {
        const resolution = await this._factResolver.resolveEdgeEndpoints(facts, edge);
        return resolution?.alive === true;
    }
}
function requireResolverFields(fields) {
    if (fields !== null && typeof fields === 'object') {
        return fields;
    }
    throw new MemoryBudgetError('CheckpointExistingEntityWriteResolver requires object fields', {
        code: 'E_MEMORY_BUDGET_INVALID',
        context: { field: 'fields' },
    });
}
