export interface EcapContext {
  visi_id?: string;
  hes_appointment_id?: string;
  signador?: string;
  campanya?: string;
}

export abstract class PrimariaContextManager {
  abstract getContext(): Readonly<EcapContext>;
}

class PrimariaContextManagerImpl implements PrimariaContextManager {
  private context: EcapContext = {};

  /**
   * Initializes the context with the provided ECAP context data.
   * This should only be called once during shell initialization.
   *
   * @param {EcapContext} context - The context data from ECAP
   * @return {void}
   */
  public initializeContext(context: EcapContext): void {
    this.context = { ...context };
  }

  /**
   * Returns a read-only copy of the entire ECAP context.
   *
   * @return {Readonly<EcapContext>} The context object
   */
  getContext(): Readonly<EcapContext> {
    return { ...this.context };
  }
}

let contextManager: PrimariaContextManagerImpl;

export const createContextManager = (): PrimariaContextManagerImpl => {
  if (contextManager) return contextManager;
  contextManager = new PrimariaContextManagerImpl();
  return contextManager;
};
