import { SleepConsolidationBatchJob } from '../jobs/sleep-consolidation-batch-job.js';
import { TelemetryCleanupBatchJob } from '../jobs/telemetry-cleanup-batch-job.js';
export async function runTelemetryCleanupBatch(ctx) {
    if (!ctx.telemetryCleanupRepository) {
        return;
    }
    if (!ctx.telemetryCleanupBatchJob.current) {
        ctx.telemetryCleanupBatchJob.current = new TelemetryCleanupBatchJob({
            repository: ctx.telemetryCleanupRepository
        });
    }
    await ctx.telemetryCleanupBatchJob.current.execute();
}
export async function runSleepConsolidationBatch(ctx) {
    try {
        if (!ctx.sleepConsolidationService) {
            throw new Error('SleepConsolidationService not configured');
        }
        if (!ctx.sleepConsolidationBatchJob.current) {
            ctx.sleepConsolidationBatchJob.current = new SleepConsolidationBatchJob({
                sleepConsolidationService: ctx.sleepConsolidationService,
                fileLogger: ctx.fileLogger
            });
        }
        const batchResult = await ctx.sleepConsolidationBatchJob.current.execute();
        ctx.lastExecution.set('sleep_consolidation_batch', new Date());
        ctx.totalExecutions.set('sleep_consolidation_batch', (ctx.totalExecutions.get('sleep_consolidation_batch') || 0) + 1);
        return batchResult;
    }
    catch (error) {
        const startTime = new Date();
        const endTime = new Date();
        const message = error instanceof Error ? error.message : String(error);
        ctx.log('Sleep consolidation batch failed', { error: message }, 'error');
        return {
            jobType: 'sleep_consolidation_batch',
            startTime,
            endTime,
            duration: endTime.getTime() - startTime.getTime(),
            success: false,
            processed: 0,
            errors: [message],
            warnings: []
        };
    }
}
//# sourceMappingURL=batch-scheduler-sleep-telemetry-handlers.js.map