import computeShardKey from "../../utils/shardKey.js";
import { CheckpointBasisFact } from "./CheckpointBasisFactBase.js";
import { eventSortKey, eventTransport, validateDirection, validateEventId, validateText, } from "./CheckpointBasisFactValidation.js";
export class CheckpointAdjacencyFact extends CheckpointBasisFact {
    kind = 'adjacency';
    direction;
    from;
    to;
    label;
    alive;
    eventId;
    constructor(options) {
        super();
        this.direction = validateDirection(options.direction);
        this.from = validateText(options.from, 'from');
        this.to = validateText(options.to, 'to');
        this.label = validateText(options.label, 'label');
        this.alive = options.alive;
        this.eventId = validateEventId(options.eventId);
        Object.freeze(this);
    }
    shardFamily() {
        return this.direction === 'outgoing' ? 'outgoing-adjacency' : 'incoming-adjacency';
    }
    shardPath() {
        const owner = this.direction === 'outgoing' ? this.from : this.to;
        return `${this.direction}_${computeShardKey(owner)}.cbor`;
    }
    sortKey() {
        return `${this.direction}:${this.from}:${this.to}:${this.label}:${eventSortKey(this.eventId)}`;
    }
    toTransport() {
        return {
            kind: this.kind,
            direction: this.direction,
            from: this.from,
            to: this.to,
            label: this.label,
            alive: this.alive,
            eventId: eventTransport(this.eventId),
        };
    }
}
