<?php

declare(strict_types=1);

namespace App\Framework\Deployment\Docker\ValueObjects;

use App\Framework\Core\ValueObjects\Duration;

/**
 * Deployment Result Value Object
 */
final readonly class DeploymentResult
{
    public function __construct(
        public ContainerId $containerId,
        public DeploymentStatus $status,
        public Duration $duration,
        public ?string $message = null,
        public ?string $error = null
    ) {
    }

    public static function success(ContainerId $containerId, Duration $duration, string $message): self
    {
        return new self(
            containerId: $containerId,
            status: DeploymentStatus::SUCCESS,
            duration: $duration,
            message: $message
        );
    }

    public static function failure(ContainerId $containerId, Duration $duration, string $error): self
    {
        return new self(
            containerId: $containerId,
            status: DeploymentStatus::FAILED,
            duration: $duration,
            error: $error
        );
    }

    public function isSuccess(): bool
    {
        return $this->status === DeploymentStatus::SUCCESS;
    }

    public function isFailed(): bool
    {
        return $this->status === DeploymentStatus::FAILED;
    }
}
