import { PrimariaApi, shellApi } from "../../api/api";
import { BrokerDisposableHandler } from "../../api/broker/primaria-broker";
import { container, registerDep, unregisterDep } from "../../infrastructure/ioc/container";
import { registerRequest } from "../utils";
import { GetUserInfoBackendAdapter } from "./backend-adapter";
import { GetUserInfoHandler } from "./handler";
import { GetUserInfo } from "./request";

let request: BrokerDisposableHandler;

export const useGetUserInfo = (api: PrimariaApi) => {
  disposeGetUserInfo();
  request = registerRequest(api, container)(GetUserInfo, GetUserInfoHandler);
  registerDep(GetUserInfoBackendAdapter);
};

export const disposeGetUserInfo = () => {
  request?.dispose();
  unregisterDep(GetUserInfoBackendAdapter);
};
