<?php

namespace App\Framework\Http;

/**
 * Value Object für IP-Adressen
 */
final readonly class IpAddress
{
    public function __construct(
        public string $value
    ) {
        if (!filter_var($value, FILTER_VALIDATE_IP)) {
            throw new \InvalidArgumentException("Invalid IP address: {$value}");
        }
    }

    public function isPrivate(): bool
    {
        return !filter_var($this->value, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE);
    }

    public function __toString(): string
    {
        return $this->value;
    }
}
