import { mediatorSettings } from "mediatr-ts";
import { PrimariaApi } from "../api/api";
import { container } from "../infrastructure/ioc/container";
import { TYPES } from "../infrastructure/ioc/types";
import { disposeExitShell, useExitShell } from "./exit/bootstrapper";
import { disposeGetUserInfo, useGetUserInfo } from "./get-user-info/bootstrapper";
import { GetUserInfo } from "./get-user-info/request";

export const useFeatures = (api: PrimariaApi) => {
  container.bind(TYPES.primaryApi).toConstantValue(api);
  useGetUserInfo(api);
  useExitShell(api);
  api.broker.send(new GetUserInfo());
};

export const disposeFeatures = (api: PrimariaApi) => {
  disposeGetUserInfo();
  disposeExitShell();
  container.unbindAll();
  api.regionManager._destroy();
  mediatorSettings.resolver.clear();
};
