import QueryError from "../../errors/QueryError.js";
export default class ReadIdentity {
    kind = 'checkpoint-tail-read';
    basis = 'checkpointReadBasis+tailWitnesses';
    worldline;
    entityAspect;
    checkpointSha;
    checkpointFrontier;
    checkpointIndexShards;
    tailWitnesses;
    reducerVersion;
    projectionVersion;
    constructor(options) {
        assertNonEmpty(options.worldline, 'worldline');
        assertNonEmpty(options.entityAspect, 'entityAspect');
        assertNonEmpty(options.checkpointSha, 'checkpointSha');
        assertNonEmpty(options.reducerVersion, 'reducerVersion');
        assertNonEmpty(options.projectionVersion, 'projectionVersion');
        this.worldline = options.worldline;
        this.entityAspect = options.entityAspect;
        this.checkpointSha = options.checkpointSha;
        this.checkpointFrontier = freezeFrontier(options.checkpointFrontier);
        this.checkpointIndexShards = freezeIndexShards(options.checkpointIndexShards);
        this.tailWitnesses = freezeTailWitnesses(options.tailWitnesses);
        this.reducerVersion = options.reducerVersion;
        this.projectionVersion = options.projectionVersion;
        Object.freeze(this);
    }
}
function assertNonEmpty(value, field) {
    if (value.length === 0) {
        throw new QueryError('read identity requires non-empty fields', {
            code: 'E_OPTIC_READ_IDENTITY',
            context: { field },
        });
    }
}
function freezeFrontier(entries) {
    return Object.freeze(entries.map((entry) => Object.freeze({
        writerId: entry.writerId,
        patchSha: entry.patchSha,
    })));
}
function freezeIndexShards(shards) {
    return Object.freeze(shards.map((shard) => Object.freeze({
        path: shard.path,
        oid: shard.oid,
    })));
}
function freezeTailWitnesses(witnesses) {
    return Object.freeze(witnesses.map((witness) => Object.freeze({
        sha: witness.sha,
        writerId: witness.writerId,
        lamport: witness.lamport,
    })));
}
