export function createTestSnapshot(overrides = {}) {
    return {
        schemaVersion: '1.0',
        scope: 'agent',
        createdAt: '2024-01-01T00:00:00.000Z',
        data: {
            messages: [],
            state: { testKey: 'testValue' },
            systemPrompt: 'You are a test assistant',
        },
        appData: {},
        ...overrides,
    };
}
export function createTestManifest(overrides = {}) {
    return {
        schemaVersion: '1.0',
        updatedAt: '2024-01-01T00:00:00.000Z',
        ...overrides,
    };
}
export function createTestScope(kind = 'agent') {
    return kind;
}
export function createTestSnapshots(count, baseSnapshot) {
    return Array.from({ length: count }, (_, i) => createTestSnapshot({
        ...baseSnapshot,
        createdAt: new Date(2024, 0, 1, 0, i).toISOString(),
    }));
}
/**
 * Mock storage implementation for testing that stores data in memory
 */
export class MockSnapshotStorage {
    snapshots = new Map();
    manifests = new Map();
    shouldThrowErrors = false;
    async saveSnapshot(params) {
        if (this.shouldThrowErrors)
            throw new Error('Mock save error');
        const { location, snapshotId, isLatest, snapshot } = params;
        const key = this.getKey(location, snapshotId);
        this.snapshots.set(key, snapshot);
        if (isLatest) {
            this.snapshots.set(this.getKey(location, 'latest'), snapshot);
        }
    }
    async loadSnapshot(params) {
        if (this.shouldThrowErrors)
            throw new Error('Mock load error');
        if (params.snapshotId === undefined) {
            return this.snapshots.get(this.getKey(params.location, 'latest')) ?? null;
        }
        return this.snapshots.get(this.getKey(params.location, params.snapshotId)) ?? null;
    }
    async listSnapshotIds(params) {
        if (this.shouldThrowErrors)
            throw new Error('Mock list error');
        const prefix = `${params.location.sessionId}::${params.location.scope}::${params.location.scopeId}::`;
        let ids = [];
        for (const [key] of this.snapshots) {
            if (key.startsWith(prefix) && !key.endsWith('::latest')) {
                ids.push(key.slice(prefix.length));
            }
        }
        ids = ids.sort();
        if (params.startAfter) {
            ids = ids.filter((id) => id > params.startAfter);
        }
        if (params.limit !== undefined) {
            ids = ids.slice(0, params.limit);
        }
        return ids;
    }
    async deleteSession(params) {
        if (this.shouldThrowErrors)
            throw new Error('Mock delete error');
        for (const key of this.snapshots.keys()) {
            if (key.startsWith(`${params.sessionId}::`))
                this.snapshots.delete(key);
        }
        for (const key of this.manifests.keys()) {
            if (key.startsWith(`${params.sessionId}::`))
                this.manifests.delete(key);
        }
    }
    async loadManifest(params) {
        if (this.shouldThrowErrors)
            throw new Error('Mock manifest load error');
        const { sessionId } = params.location;
        if (!sessionId) {
            throw new Error('Invalid sessionId: cannot be empty or undefined');
        }
        const key = this.getManifestKey(params.location);
        return (this.manifests.get(key) ?? {
            schemaVersion: '1.0',
            updatedAt: new Date().toISOString(),
        });
    }
    async saveManifest(params) {
        if (this.shouldThrowErrors)
            throw new Error('Mock manifest save error');
        const { sessionId } = params.location;
        if (!sessionId) {
            throw new Error('Invalid sessionId: cannot be empty or undefined');
        }
        this.manifests.set(this.getManifestKey(params.location), params.manifest);
    }
    getKey(location, snapshotId) {
        if (!location.sessionId) {
            throw new Error('Invalid sessionId: cannot be empty or undefined');
        }
        return `${location.sessionId}::${location.scope}::${location.scopeId}::${snapshotId}`;
    }
    getManifestKey(location) {
        if (!location.sessionId) {
            throw new Error('Invalid sessionId: cannot be empty or undefined');
        }
        return `${location.sessionId}::${location.scope}::${location.scopeId}::manifest`;
    }
}
//# sourceMappingURL=mock-storage-provider.js.map