import GraphModelMigrationLoweredOperation from "./GraphModelMigrationLoweredOperation.js";
import WarpError from "../errors/WarpError.js";
/** One scratch-history commit written for a lowered migration operation. */
export default class GraphModelMigrationScratchWrittenPatch {
    commitId;
    operation;
    sequence;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.commitId = requireNonEmptyString(checkedFields.commitId, 'commitId');
        this.operation = requireOperation(checkedFields.operation);
        this.sequence = requireNonNegativeInteger(checkedFields.sequence, 'sequence');
        Object.freeze(this);
    }
    /** Returns the deterministic lowered operation key carried by this commit. */
    operationKey() {
        return this.operation.toKey();
    }
}
function requireFields(fields) {
    if (fields === null || fields === undefined) {
        throw new WarpError('GraphModelMigrationScratchWrittenPatch fields must be provided', 'E_VALIDATION');
    }
    return fields;
}
function requireOperation(operation) {
    if (!(operation instanceof GraphModelMigrationLoweredOperation)) {
        throw new WarpError('operation must be a GraphModelMigrationLoweredOperation', 'E_VALIDATION');
    }
    return operation;
}
function requireNonEmptyString(value, name) {
    if (typeof value !== 'string' || value.length === 0) {
        throw new WarpError(`${name} must be a non-empty string`, 'E_VALIDATION');
    }
    return value;
}
function requireNonNegativeInteger(value, name) {
    if (!Number.isInteger(value) || value < 0) {
        throw new WarpError(`${name} must be a non-negative integer`, 'E_VALIDATION');
    }
    return value;
}
