/**
 * Mock OpenTelemetry Span for testing tracer functionality.
 * Implements the full Span interface and records all calls for assertion.
 */
/**
 * Concrete mock implementing the Span interface.
 * Chainable methods return `this` to satisfy the `Span` contract.
 */
export class MockSpan {
    calls = {
        setAttribute: [],
        setAttributes: [],
        addEvent: [],
        setStatus: [],
        updateName: [],
        end: [],
        recordException: [],
    };
    /** @returns A fixed span context for test assertions. */
    spanContext() {
        return { traceId: 'trace-1', spanId: 'span-1', traceFlags: 1 };
    }
    /** Records a single attribute. */
    setAttribute(key, value) {
        this.calls.setAttribute.push({ key, value });
        return this;
    }
    /** Records a batch of attributes. */
    setAttributes(attributes) {
        this.calls.setAttributes.push({ attributes });
        for (const [key, value] of Object.entries(attributes)) {
            if (value !== undefined)
                this.setAttribute(key, value);
        }
        return this;
    }
    /** Records a span event with optional attributes. */
    addEvent(name, attributesOrStartTime, startTime) {
        this.calls.addEvent.push({ name, attributes: attributesOrStartTime, startTime });
        return this;
    }
    /** No-op link addition. */
    addLink(_link) {
        return this;
    }
    /** No-op batch link addition. */
    addLinks(_links) {
        return this;
    }
    /** Records a status change. */
    setStatus(status) {
        this.calls.setStatus.push({ status });
        return this;
    }
    /** Records a name update. */
    updateName(name) {
        this.calls.updateName.push({ name });
        return this;
    }
    /** Records span end. */
    end(endTime) {
        this.calls.end.push({ endTime });
    }
    /** Always returns true for mock spans. */
    isRecording() {
        return true;
    }
    /** Records an exception. */
    recordException(exception, time) {
        this.calls.recordException.push({ exception, time });
    }
    /**
     * Get the value of a specific attribute set via setAttribute.
     */
    getAttributeValue(key) {
        const entry = this.calls.setAttribute.find((c) => c.key === key);
        return entry?.value;
    }
    /**
     * Get all events with a given name.
     */
    getEvents(name) {
        return this.calls.addEvent.filter((c) => c.name === name);
    }
}
/**
 * Extract a string attribute from a mock span event's attributes.
 */
export function eventAttr(event, key) {
    const attrs = event.attributes;
    return attrs[key];
}
//# sourceMappingURL=mock-span.js.map