<?php

declare(strict_types=1);

namespace CpCreation\AltchaBundle\Model;

final readonly class ScopePolicy
{
    public function __construct(
        public string $scope,
        public bool $enabled,
        public int $version,
        public bool $altchaEnabled,
        public ?string $profile,
        public int $minimumFillTimeMs,
        public int $maximumEnvelopeAgeSeconds,
        public bool $subjectLimitsEnabled,
        public int $securityEpoch = 1,
    ) {
        if (1 > $version) {
            throw new \InvalidArgumentException('A policy version must be positive.');
        }
        if (0 > $minimumFillTimeMs || 1 > $maximumEnvelopeAgeSeconds) {
            throw new \InvalidArgumentException('Invalid timing policy.');
        }
        if ($enabled && $altchaEnabled && (null === $profile || '' === trim($profile))) {
            throw new \InvalidArgumentException('An enabled ALTCHA policy requires a crypto profile.');
        }
    }
}
