import { TYPES } from "../../infrastructure/ioc/types";
import { inject } from "inversify";
import { GetUserInfo } from "./request";
import { IUserInfo } from "./model";
import { UserInfoBackendAdapter } from "./backend-adapter";
import { GetUserInfoBackendAdapter } from "./backend-adapter";
import { PrimariaApi } from "../../api/api";

export class GetUserInfoHandler {
  constructor(
    @inject(TYPES.primaryApi) private api: PrimariaApi,
    @inject(GetUserInfoBackendAdapter) private backendAdapter: UserInfoBackendAdapter,
  ) {}
  async handle(message: GetUserInfo): Promise<IUserInfo | undefined> {
    try {
      const userInfo = await this.backendAdapter.getUserInfo();
      this.api.globalStateManager.setData("userInfo", userInfo);
      return userInfo;
    } catch (error) {
      this.api.notificationService.error(error.message);
    }
  }
}
