import { WorkspaceService } from './workspace.service.js';
const DEFAULT_SCAN_INTERVAL_MS = 60 * 60 * 1000; // 1 hour
const DEFAULT_IDLE_THRESHOLD_HOURS = 24;
export class HibernationScheduler {
    scanIntervalMs;
    idleThresholdHours;
    timer = null;
    running = false;
    constructor(scanIntervalMs = DEFAULT_SCAN_INTERVAL_MS, idleThresholdHours = DEFAULT_IDLE_THRESHOLD_HOURS) {
        this.scanIntervalMs = scanIntervalMs;
        this.idleThresholdHours = idleThresholdHours;
    }
    start() {
        if (this.timer)
            return;
        console.log(`[HibernationScheduler] Started (interval: ${this.scanIntervalMs / 60000}min, threshold: ${this.idleThresholdHours}h)`);
        this.timer = setInterval(() => {
            this.scan().catch((err) => {
                console.error('[HibernationScheduler] Scan failed:', err);
            });
        }, this.scanIntervalMs);
        // Run initial scan after a short delay to let services initialize
        setTimeout(() => {
            this.scan().catch((err) => {
                console.error('[HibernationScheduler] Initial scan failed:', err);
            });
        }, 10_000);
    }
    stop() {
        if (this.timer) {
            clearInterval(this.timer);
            this.timer = null;
            console.log('[HibernationScheduler] Stopped');
        }
    }
    async scan() {
        if (this.running)
            return;
        this.running = true;
        try {
            const service = new WorkspaceService();
            await service.cleanup();
            await service.hibernateIdle(this.idleThresholdHours);
        }
        finally {
            this.running = false;
        }
    }
}
//# sourceMappingURL=hibernation-scheduler.js.map