import { Processor, WorkerHost } from "@nestjs/bullmq";
import { Injectable, Inject } from "@nestjs/common";
import { Logger } from "nestjs-pino";
import { EmailService } from "../email.service";
import type { EmailJobData } from "./email.queue";
import { QUEUE_NAMES } from "../../queue/queue.constants";

@Processor(QUEUE_NAMES.EMAIL)
@Injectable()
export class EmailProcessor extends WorkerHost {
  constructor(
    private readonly emailService: EmailService,
    @Inject(Logger) private readonly logger: Logger
  ) {
    super();
  }

  async process(job: { data: EmailJobData }): Promise<void> {
    await this.emailService.sendEmail(job.data);
    this.logger.debug("Processed email job");
  }
}
