<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\services;

use apexl\Config\ConfigurationInterface;
use apexl\Config\Exceptions\MissingConfigException;
use apexl\Io\modules\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'))
        );
    }
}