import { ITransactionManager } from "@/core/common/infrastructure/database";
import { Token } from "../../domain";
import { IAuthService } from "../../domain/services";

export class RefreshTokenUseCase {
  constructor(
    private readonly authService: IAuthService,
    private readonly transactionManager: ITransactionManager
  ) {}

  public async execute(token: Token) {
    return await this.transactionManager.complete(async (transaction) => {
      const payloadData = this.authService.verifyRefreshToken(token);

      /*if (!payload || !payload.email || !payload.user_id || !payload.tab_id || !payload.roles) {
        return Result.fail(new Error("Invalid input data"));
      }*/

      return this.authService.generateRefreshToken({
        ...payloadData,
      });
    });
  }
}
