/**
 * BullMQ AI report processor — DISABLED.
 * Reports are generated via in-process background (setImmediate) in AiReportService.
 * Uncomment this class and re-register it in campaign.module when re-enabling BullMQ.
 */
/*
import { Logger, OnModuleInit } from '@nestjs/common';
import { Processor, WorkerHost, OnWorkerEvent } from '@nestjs/bullmq';
import { Job } from 'bullmq';
import { AiReportService } from './ai-report.service';
import {
    AI_REPORT_QUEUE,
    AI_REPORT_JOB_OPTIONS,
    AiReportJobData,
} from 'src/common/services/queue/queue.constants';

@Processor(AI_REPORT_QUEUE, {
    concurrency: AI_REPORT_JOB_OPTIONS.concurrency,
    lockDuration: AI_REPORT_JOB_OPTIONS.lockDurationMs,
})
export class AiReportProcessor extends WorkerHost implements OnModuleInit {
    private readonly logger = new Logger(AiReportProcessor.name);

    constructor(private readonly aiReportService: AiReportService) {
        super();
    }

    async onModuleInit() {
        this.logger.log(`Listening on queue "${AI_REPORT_QUEUE}" (in-process)`);
        try {
            const recovered = await this.aiReportService.processPendingAiReports(20);
            this.logger.log(
                `Recovered ${recovered?.data?.enqueued_count ?? 0} stuck Pending AI reports`,
            );
        } catch (error: any) {
            this.logger.error(`Failed to recover Pending AI reports: ${error?.message || error}`);
        }
    }

    async process(job: Job<AiReportJobData>): Promise<void> {
        const { reportId } = job.data;
        const attempt = (job.attemptsMade || 0) + 1;
        const maxAttempts = job.opts.attempts ?? AI_REPORT_JOB_OPTIONS.attempts;
        this.logger.log(
            `[AI Report ${reportId}] QUEUE=active | processor started | attempt ${attempt}/${maxAttempts}`,
        );

        await this.aiReportService.processAiReportJob(reportId, {
            isLastAttempt: attempt >= maxAttempts,
            isRetry: attempt > 1,
        });
    }

    @OnWorkerEvent('active')
    onActive(job: Job<AiReportJobData>) {
        const attempt = (job.attemptsMade || 0) + 1;
        this.logger.log(`[AI Report ${job.data?.reportId || job.id}] QUEUE=active | picked from Redis | attempt ${attempt}`);
    }

    @OnWorkerEvent('completed')
    onCompleted(job: Job<AiReportJobData>) {
        this.logger.log(`[AI Report ${job.data?.reportId || job.id}] QUEUE=completed | Redis job finished OK`);
    }

    @OnWorkerEvent('failed')
    onFailed(job: Job<AiReportJobData>, error: Error) {
        const attempt = job?.attemptsMade || 0;
        const maxAttempts = job?.opts?.attempts ?? AI_REPORT_JOB_OPTIONS.attempts;
        const willRetry = attempt < maxAttempts;
        this.logger.error(
            `[AI Report ${job?.data?.reportId || job?.id}] QUEUE=${willRetry ? 'waiting-retry' : 'failed'} | attempt ${attempt}/${maxAttempts} | ${error?.message}`,
        );
    }

    @OnWorkerEvent('stalled')
    onStalled(jobId: string) {
        this.logger.warn(`[AI Report ${jobId}] QUEUE=stalled | lock expired, BullMQ will retry`);
    }

    @OnWorkerEvent('error')
    onError(error: Error) {
        this.logger.error(`BullMQ processor error: ${error?.message || error}`);
    }
}
*/
