import { OltService } from '../olt/olt.service';

export class LaserScraperWorker {
  private static isRunning = false;

  public static async executeScan() {
    if (this.isRunning) return [];
    this.isRunning = true;
    try {
      return await OltService.runLaserDiagnosticsScrape();
    } finally {
      this.isRunning = false;
    }
  }

  public static startScheduler(intervalMs = 15 * 60 * 1000) {
    console.log(`[LaserScraperWorker] Initialized 15-minute OLT laser scraper loop.`);
    setInterval(async () => {
      try {
        const results = await this.executeScan();
        console.log(`[LaserScraperWorker] Polled ${results.length} ONUs optical health parameters.`);
      } catch (err) {
        console.error('[LaserScraperWorker] Polling error:', err);
      }
    }, intervalMs);
  }
}
