<?php

declare(strict_types=1);

namespace App\Framework\Process\ValueObjects\Network;

/**
 * Port Status Result.
 */
final readonly class PortStatus
{
    public function __construct(
        public int $port,
        public bool $isOpen,
        public string $service = ''
    ) {
    }

    /**
     * Erstellt einen offenen Port.
     */
    public static function open(int $port, string $service = ''): self
    {
        return new self($port, true, $service);
    }

    /**
     * Erstellt einen geschlossenen Port.
     */
    public static function closed(int $port): self
    {
        return new self($port, false);
    }

    /**
     * Konvertiert zu Array.
     *
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'port' => $this->port,
            'is_open' => $this->isOpen,
            'service' => $this->service,
        ];
    }
}
