import { Injectable } from '@nestjs/common';
import { LoginAdminQueueManager } from './managers/admin-queue/login-admin-queue.manager';
import { LogoutAdminQueueManager } from './managers/admin-queue/logout-admin-queue.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 AuthAdminQueueOrchestrator {
  constructor(
    private loginManager: LoginAdminQueueManager,
    private logoutManager: LogoutAdminQueueManager,
    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(userId?: string): Promise<any> {
    if (userId) this.logoutManager.setData({ user_id: userId });
    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);
  }
}
