import WarpError from "../errors/WarpError.js";
import { TickReceipt } from "../types/TickReceipt.js";
/** Explanatory receipt shell facts that sit above the local witness core. */
export default class GitWarpTickReceiptShell {
    patchSha;
    outcomeCount;
    reasonCount;
    constructor(fields) {
        const receipt = requireReceipt(requireFields(fields).receipt);
        this.patchSha = receipt.patchSha;
        this.outcomeCount = receipt.ops.length;
        this.reasonCount = countReasons(receipt);
        Object.freeze(this);
    }
    /** Returns true when the receipt shell carries explanatory reason text. */
    hasExplanatoryReasons() {
        return this.reasonCount > 0;
    }
}
/** Validates the receipt-shell constructor envelope. */
function requireFields(value) {
    if (value === null || value === undefined) {
        throw new WarpError('GitWarpTickReceiptShell fields must be provided', 'E_VALIDATION');
    }
    return value;
}
/** Validates a TickReceipt carrier. */
function requireReceipt(value) {
    if (!(value instanceof TickReceipt)) {
        throw new WarpError('receipt must be a TickReceipt', 'E_VALIDATION');
    }
    return value;
}
/** Counts explanatory reason fields on receipt outcomes. */
function countReasons(receipt) {
    let reasonCount = 0;
    for (const op of receipt.ops) {
        if (op.reason !== undefined) {
            reasonCount += 1;
        }
    }
    return reasonCount;
}
