/**
 * PropSet — raw/wire-format property operation.
 *
 * This is the persisted form. Edge properties use a \x01-prefixed node
 * field. See NodePropSet and EdgePropSet for the canonical (internal)
 * representations.
 */
import Op from "./Op.js";
import { OP_SCOPE_RAW } from "./OpScope.js";
import { assertNonEmptyString, assertNoReservedBytes } from "./validate.js";
import { encodePropKey, EDGE_PROP_PREFIX } from "../../services/KeyCodec.js";
import { mutateProp, snapshotProp, accumulatePropDiff } from "./propHelpers.js";
import PatchError from "../../errors/PatchError.js";
import ReceiptBuilder from "../../services/ReceiptBuilder.js";
export default class PropSet extends Op {
    receiptName = 'PropSet';
    node;
    key;
    value; // nosemgrep: ts-no-unknown-outside-adapters -- 0025B
    constructor(node, key, value) {
        super('PropSet', OP_SCOPE_RAW);
        assertNonEmptyString(node, 'PropSet', 'node');
        assertNonEmptyString(key, 'PropSet', 'key');
        assertNoReservedBytes(key, 'PropSet', 'key');
        this.node = node;
        this.key = key;
        this.value = value;
        Object.freeze(this);
    }
    validate() { }
    mutate(state, eventId) {
        if (this.node[0] === EDGE_PROP_PREFIX) {
            throw new PatchError('Unnormalized legacy edge-property PropSet reached canonical apply path. ' +
                'Call normalizeRawOp() at the decode boundary.', { context: { opType: 'PropSet', node: this.node } });
        }
        mutateProp(state, encodePropKey(this.node, this.key), eventId, this.value);
    }
    outcome(state, eventId) {
        return ReceiptBuilder.propSetOutcome(state, { node: this.node, key: this.key }, eventId);
    }
    snapshot(state) {
        return snapshotProp(state, encodePropKey(this.node, this.key));
    }
    accumulate(diff, state, before) {
        accumulatePropDiff(diff, state, this.node, this.key, before);
    }
}
