<?php

declare(strict_types=1);

namespace App\Framework\Deployment\Pipeline\ValueObjects;

use App\Framework\Core\ValueObjects\Duration;

/**
 * Pipeline Stage Execution Result
 *
 * Represents the outcome of executing a single pipeline stage.
 */
final readonly class StageResult
{
    public function __construct(
        public PipelineStage $stage,
        public bool $success,
        public Duration $duration,
        public ?string $output = null,
        public ?string $error = null
    ) {}

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

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

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

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