import { IamFindUserByUsernamePasswordService } from '@app/iam/user';
import type { ICredentialVerifier } from '@aurora/modules/authentication/domain/ports';
import { Injectable } from '@nestjs/common';

@Injectable()
export class IamCredentialVerifierAdapter implements ICredentialVerifier {
  constructor(private readonly findUserByUsernamePassword: IamFindUserByUsernamePasswordService) {}

  async verify(username: string, password: string): Promise<{ accountId: string } | null> {
    const user = await this.findUserByUsernamePassword.main(username, password);
    if (!user) return null;
    return { accountId: user.accountId };
  }
}
