import {
  IRepositoryManager,
  RepositoryManager,
} from "@/contexts/common/domain";
import {
  ISequelizeAdapter,
  createSequelizeAdapter,
} from "@/contexts/common/infrastructure/sequelize";
import { InvoicingServices, TInvoicingServices } from "../application";

export interface IInvoicingContext {
  adapter: ISequelizeAdapter;
  repositoryManager: IRepositoryManager;
  services: TInvoicingServices;
}

class InvoicingContext {
  private static instance: InvoicingContext | null = null;
  public static getInstance(): InvoicingContext {
    if (!InvoicingContext.instance) {
      InvoicingContext.instance = new InvoicingContext();
    }

    return InvoicingContext.instance;
  }

  private context: IInvoicingContext;

  private constructor() {
    this.context = {
      adapter: createSequelizeAdapter(),
      repositoryManager: RepositoryManager.getInstance(),
      services: InvoicingServices,
    };
  }

  public getContext(): IInvoicingContext {
    return this.context;
  }
}

const sharedInvoicingContext = InvoicingContext.getInstance().getContext();
export { sharedInvoicingContext };
