<?php

declare(strict_types=1);

namespace App\Administration\Infrastructure\Security;

use App\Administration\Application\Port\PasswordHasher;
use Override;
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;

/**
 * Symfony implementation of the PasswordHasher port.
 *
 * Uses Symfony's PasswordHasher component with Argon2id algorithm.
 */
final readonly class SymfonyPasswordHasher implements PasswordHasher
{
    private const string HASHER_ID = 'common';

    public function __construct(
        private PasswordHasherFactoryInterface $hasherFactory,
    ) {
    }

    #[Override]
    public function hash(string $plainPassword): string
    {
        return $this->hasherFactory
            ->getPasswordHasher(self::HASHER_ID)
            ->hash($plainPassword);
    }

    #[Override]
    public function verify(string $hashedPassword, string $plainPassword): bool
    {
        return $this->hasherFactory
            ->getPasswordHasher(self::HASHER_ID)
            ->verify($hashedPassword, $plainPassword);
    }
}
