/**
 * SessionView — typed wrapper over Session[] with collection helpers.
 *
 * Provides discoverable query methods for common session lookups.
 * Does NOT change the DataAccessor interface — consumers create views from Session[].
 *
 * Usage:
 *   const sessions = await accessor.loadSessions();
 *   const view = SessionView.from(sessions);
 *   const active = view.findActive();
 *
 * @epic T4454
 */
export class SessionView {
    _sessions;
    constructor(sessions) {
        this._sessions = sessions;
    }
    /** Create a SessionView from a Session array. */
    static from(sessions) {
        return new SessionView(sessions);
    }
    /** All sessions in the view (readonly). */
    get all() {
        return this._sessions;
    }
    /** Number of sessions. */
    get length() {
        return this._sessions.length;
    }
    /** Find the currently active session (if any). */
    findActive() {
        return this._sessions.find((s) => s.status === 'active');
    }
    /** Find a session by ID. */
    findById(id) {
        return this._sessions.find((s) => s.id === id);
    }
    /** Filter sessions by one or more statuses. */
    filterByStatus(...statuses) {
        return this._sessions.filter((s) => statuses.includes(s.status));
    }
    /** Find sessions matching a scope type and optional rootTaskId. */
    findByScope(type, rootTaskId) {
        return this._sessions.filter((s) => {
            if (s.scope?.type !== type)
                return false;
            if (rootTaskId && s.scope?.rootTaskId !== rootTaskId)
                return false;
            return true;
        });
    }
    /** Sort sessions by a date field. Returns a new array (does not mutate). */
    sortByDate(field, descending = true) {
        return [...this._sessions].sort((a, b) => {
            const aDate = new Date(a[field] || '').getTime();
            const bDate = new Date(b[field] || '').getTime();
            return descending ? bDate - aDate : aDate - bDate;
        });
    }
    /** Get the most recently started session. */
    mostRecent() {
        if (this._sessions.length === 0)
            return undefined;
        return this.sortByDate('startedAt', true)[0];
    }
    /** Convert back to a plain Session array (shallow copy). */
    toArray() {
        return [...this._sessions];
    }
    /** Support for-of iteration. */
    [Symbol.iterator]() {
        return this._sessions[Symbol.iterator]();
    }
}
//# sourceMappingURL=session-view.js.map