<?php

declare(strict_types=1);

namespace App\Framework\Process\ValueObjects\Docker;

/**
 * Docker Container Information.
 */
final readonly class DockerContainer
{
    public function __construct(
        public string $id,
        public string $name,
        public string $image,
        public string $status,
        public bool $isRunning,
        public ?string $created = null,
        public array $ports = []
    ) {
    }

    /**
     * Erstellt Container aus Docker-Output.
     */
    public static function fromDockerPs(string $id, string $name, string $image, string $status): self
    {
        $isRunning = str_starts_with(strtolower($status), 'up');

        return new self(
            id: $id,
            name: $name,
            image: $image,
            status: $status,
            isRunning: $isRunning
        );
    }

    /**
     * Konvertiert zu Array.
     *
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'image' => $this->image,
            'status' => $this->status,
            'is_running' => $this->isRunning,
            'created' => $this->created,
            'ports' => $this->ports,
        ];
    }
}
