/**
 * RegisterUser use case. Orchestrates domain + ports; knows no HTTP.
 */
import type { PasswordHasher, UserRepository } from '../domain/ports.js';
import type { User } from '../domain/user.js';
import { normalizeEmail } from '../domain/user.js';

export interface RegisterInput {
  email: string;
  password: string;
}

export class RegisterUser {
  constructor(
    private readonly users: UserRepository,
    private readonly hasher: PasswordHasher,
  ) {}

  async execute(input: RegisterInput): Promise<User> {
    const email = normalizeEmail(input.email);
    const passwordHash = await this.hasher.hash(input.password);
    return this.users.create({ email, passwordHash });
  }
}
