<?php

declare(strict_types=1);

namespace Apexl\Io\User\Services;

use Apexl\Config\ConfigurationInterface;
use Apexl\Config\Exceptions\MissingConfigException;
use Apexl\Io\User\Interfaces\TokenHasherInterface;

final readonly class NativeTokenHasher implements TokenHasherInterface
{
    public function __construct(private ConfigurationInterface $config) {}

    /**
     * @throws MissingConfigException
     */
    public function hash(string $token): string
    {
        return hash(
            $this->config->get('auth.refresh.algorithm'),
            sprintf('%s%s', $token, $this->config->get('auth.refresh.salt'))
        );
    }
}