import Sink from "../../domain/stream/Sink.js";
import WarpError from "../../domain/errors/WarpError.js";
/**
 * Stream sink that accumulates [path, oid] entries and assembles them
 * into a Git tree on finalization.
 *
 * Consumes: `[string, string]` — path + blob OID
 * Produces: `string` — the Git tree OID
 */
export class TreeAssemblerSink extends Sink {
    _treePort;
    _entries;
    constructor(treePort) {
        super();
        if (treePort === null || treePort === undefined) {
            throw new WarpError('TreeAssemblerSink requires a treePort', 'E_INVALID_DEPENDENCY');
        }
        this._treePort = treePort;
        this._entries = [];
    }
    /**
     * Accepts a [path, oid] entry and formats it for mktree.
     */
    _accept(item) {
        const [path, oid] = item;
        this._entries.push(`100644 blob ${oid}\t${path}`);
    }
    /**
     * Builds the Git tree from accumulated entries.
     */
    async _finalize() {
        this._entries.sort();
        return await this._treePort.writeTree(this._entries);
    }
}
