<?php

declare(strict_types=1);

namespace App\Framework\Deployment\Docker\ValueObjects;

use App\Framework\Core\ValueObjects\Duration;

/**
 * Docker Compose Operation Result
 *
 * Encapsulates the outcome of a docker-compose operation.
 */
final readonly class ComposeResult
{
    public function __construct(
        public string $operation,
        public bool $success,
        public Duration $duration,
        public ?string $output = null,
        public ?string $error = null
    ) {}

    public static function success(
        string $operation,
        Duration $duration,
        string $output
    ): self {
        return new self(
            operation: $operation,
            success: true,
            duration: $duration,
            output: $output,
            error: null
        );
    }

    public static function failure(
        string $operation,
        Duration $duration,
        string $error
    ): self {
        return new self(
            operation: $operation,
            success: false,
            duration: $duration,
            output: null,
            error: $error
        );
    }

    public function isSuccess(): bool
    {
        return $this->success;
    }

    public function isFailed(): bool
    {
        return !$this->success;
    }
}
