<?php

declare(strict_types=1);

namespace App\Framework\Exception;

final class ConsoleException extends FrameworkException
{
    public static function commandFailed(string $command, int $exitCode, string $output = ''): self
    {
        $context = ExceptionContext::forOperation('console.command', 'ConsoleRunner')
            ->withData([
                'command' => $command,
                'exit_code' => $exitCode,
                'output' => $output,
                'working_directory' => getcwd()
            ]);

        return new self("Console command failed: {$command}", $exitCode, null, $context);
    }

    public static function commandNotFound(string $command): self
    {
        $context = ExceptionContext::forOperation('console.command_lookup', 'ConsoleRunner')
            ->withData([
                'command' => $command
            ]);

        return new self("Console command not found: {$command}", 404, null, $context);
    }

    public static function invalidArguments(string $command, array $arguments, array $errors): self
    {
        $context = ExceptionContext::forOperation('console.argument_validation', 'ConsoleRunner')
            ->withData([
                'command' => $command,
                'arguments' => $arguments,
                'validation_errors' => $errors
            ]);

        return new self("Invalid arguments for command: {$command}", 400, null, $context);
    }
}
