// src/lib/controller.js
// Copyright (C) 2026 Robert Colbert <rob.colbert@openplatform.us>
// All Rights Reserved

import env from "../config/env.js";
import BullQueue from "bull";

import { GadgetComponent, GadgetLog } from "@gadget/api";

export abstract class DtpWorker implements GadgetComponent {
  log: GadgetLog;
  jobQueue: BullQueue.Queue | undefined;

  abstract get name(): string;
  abstract get slug(): string;
  abstract get queueName(): string;

  constructor() {
    this.log = new GadgetLog(this);
  }

  async start(): Promise<void> {
    this.log.info("Starting worker");
    this.log.info("connecting to Bull queue on Redis", {
      queueName: this.queueName,
    });
    this.jobQueue = new BullQueue(this.queueName, { redis: env.redis });
  }

  abstract stop(): Promise<void>;
}
