import { PasswordHash } from '../value-objects/PasswordHash';

/**
 * Domain Service: PasswordHashingService
 *
 * Service for password hashing and verification.
 */
export interface IPasswordHashingService {
  hash(plain: string): Promise<string>;
  verify(plain: string, hash: string): Promise<boolean>;
}

/**
 * Implementation using bcrypt via PasswordHash VO.
 */
export class PasswordHashingService implements IPasswordHashingService {
  async hash(plain: string): Promise<string> {
    const passwordHash = await PasswordHash.create(plain);
    return passwordHash.value;
  }

  async verify(plain: string, hash: string): Promise<boolean> {
    const passwordHash = PasswordHash.fromHash(hash);
    return passwordHash.verify(plain);
  }
}