<?php

declare(strict_types=1);

namespace FecaMailshots\Infrastructure;

use FecaMailshots\Application\SecretKeyProvider;

final class EnvSecretKeyProvider implements SecretKeyProvider
{
    private string $envKey;

    public function __construct(string $envKey = 'MAILSHOTS_FIXTURE_SECRET_KEY')
    {
        $this->envKey = $envKey;
    }

    public function keyMaterial(): string
    {
        $value = getenv($this->envKey);
        if (!is_string($value) || trim($value) === '') {
            throw new \RuntimeException('Missing fixture secret key env: ' . $this->envKey);
        }
        return trim($value);
    }
}
