<?php

declare(strict_types=1);

use App\Framework\Process\ValueObjects\Command;

describe('Command Value Object', function () {
    it('can be created from string', function () {
        $command = Command::fromString('ls -la');

        expect($command->value)->toBe('ls -la')
            ->and($command->toString())->toBe('ls -la')
            ->and($command->isArray())->toBeFalse();
    });

    it('can be created from array', function () {
        $command = Command::fromArray(['ls', '-la']);

        expect($command->value)->toBe(['ls', '-la'])
            ->and($command->isArray())->toBeTrue();
    });

    it('escapes array commands when converting to string', function () {
        $command = Command::fromArray(['echo', 'hello world']);

        expect($command->toString())->toBe("'echo' 'hello world'");
    });

    it('throws exception for empty string command', function () {
        Command::fromString('');
    })->throws(InvalidArgumentException::class, 'Command string cannot be empty');

    it('throws exception for empty array command', function () {
        Command::fromArray([]);
    })->throws(InvalidArgumentException::class, 'Command array cannot be empty');

    it('handles special characters in array commands', function () {
        $command = Command::fromArray(['echo', '$USER']);

        $string = $command->toString();
        expect($string)->toContain('$USER');
    });
});
