/**
 * Logout use case: revoke the session identified by the token hash.
 * Idempotent by design.
 */
import type { SessionRepository } from '../domain/ports.js';

export class Logout {
  constructor(
    private readonly sessions: SessionRepository,
    private readonly hashToken: (token: string) => string,
  ) {}

  async execute(rawToken: string | undefined): Promise<void> {
    if (!rawToken) {
      return;
    }
    await this.sessions.revokeByTokenHash(this.hashToken(rawToken));
  }
}
