import { RepositoryManager } from "@/contexts/common/domain";
import { IContext } from "@/contexts/common/infrastructure";
import { createSequelizeAdapter } from "@/contexts/common/infrastructure/sequelize";
import { Dealer, IQuoteReferenceGeneratorService } from "../domain";

export interface ISalesContext extends IContext {
  services?: {
    QuoteReferenceGeneratorService: IQuoteReferenceGeneratorService;
  };
  dealer?: Dealer;
}

export class SalesContext {
  private static instance: SalesContext | null = null;

  public static getInstance(): ISalesContext {
    if (!SalesContext.instance) {
      SalesContext.instance = new SalesContext({
        adapter: createSequelizeAdapter(),
        repositoryManager: RepositoryManager.getInstance(),
      });
    }

    return SalesContext.instance.context;
  }

  private context: ISalesContext;

  private constructor(context: ISalesContext) {
    this.context = context;
  }
}
