import { Injectable } from '@nestjs/common';
import { LoginManager } from './managers/login.manager';
import { LogoutManager } from './managers/logout.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';

@Injectable()
export class AuthOrchestrator {
  constructor(
    private loginManager: LoginManager,
    private logoutManager: LogoutManager,
    private serviceData: UserDataService,
  ) {}

  async login(data): Promise<any> {
    this.loginManager.setData(data);
    this.loginManager.setService(this.serviceData, TABLE_NAME.USER);
    await this.loginManager.execute();
    return this.loginManager.getResult();
  }

  async logout(): Promise<any> {
    this.logoutManager.setService(this.serviceData, TABLE_NAME.USER);
    await this.logoutManager.execute();
    return this.logoutManager.getResult();
  }

  async forceLogout(token): Promise<any> {
    return this.serviceData.forceLogout(token);
  }
}
