<?php

namespace App\Framework\Smartlinks;

use DateTimeImmutable;
use InvalidArgumentException;

final readonly class TokenConfig
{
    public function __construct(
        public int $expiryHours = 24,
        public bool $oneTimeUse = false,
        public int $maxUses = 1,
        public bool $requireSecureContext = false,
        public array $allowedIpRanges = [],
        public array $metadata = []
    ) {
        if ($expiryHours <= 0) {
            throw new InvalidArgumentException('Expiry hours must be positive');
        }

        if ($maxUses <= 0) {
            throw new InvalidArgumentException('Max uses must be positive');
        }
    }

    public function getExpiryDateTime(): DateTimeImmutable
    {
        return new DateTimeImmutable("+{$this->expiryHours} hours");
    }
}
