<?php

declare(strict_types=1);

namespace App\Framework\Console;

/**
 * Result of a single workflow step execution
 */
final readonly class StepResult
{
    public function __construct(
        private bool $success,
        private string $command,
        private string $error = '',
        private array $output = [],
        private int $exitCode = 0,
        private float $executionTime = 0.0
    ) {
    }

    /**
     * Create success result
     */
    public static function success(string $command, array $output = [], int $exitCode = 0, float $executionTime = 0.0): self
    {
        return new self(true, $command, '', $output, $exitCode, $executionTime);
    }

    /**
     * Create error result
     */
    public static function error(string $error, string $command = '', array $output = [], int $exitCode = 1, float $executionTime = 0.0): self
    {
        return new self(false, $command, $error, $output, $exitCode, $executionTime);
    }

    /**
     * Check if step was successful
     */
    public function isSuccess(): bool
    {
        return $this->success;
    }

    /**
     * Check if step failed
     */
    public function isError(): bool
    {
        return ! $this->success;
    }

    /**
     * Get command that was executed
     */
    public function getCommand(): string
    {
        return $this->command;
    }

    /**
     * Get error message
     */
    public function getError(): string
    {
        return $this->error;
    }

    /**
     * Get command output
     */
    public function getOutput(): array
    {
        return $this->output;
    }

    /**
     * Get exit code
     */
    public function getExitCode(): int
    {
        return $this->exitCode;
    }

    /**
     * Get execution time in seconds
     */
    public function getExecutionTime(): float
    {
        return $this->executionTime;
    }
}
