<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;

final class RulesEvaluateCommand extends AbstractCommand
{
    public function name(): string { return 'rules:evaluate'; }
    public function description(): string { return 'PPphp Rules Evaluate'; }

    public function handle(array $arguments = []): int
    {
        $this->title('PPphp Rules Evaluate');
        $runtime = \PpPhp\Core\Platform\Rules\RulesRuntime::instance(\PpPhp\Core\Platform\Console\ConsolePath::basePath()); $runtime->registerRuleSet(\PpPhp\Core\Platform\Rules\RuleSet::create('console_rules', 'Console Rules', [\PpPhp\Core\Platform\Rules\RuleDefinition::create('console_rule', 'Console Rule', [\PpPhp\Core\Platform\Rules\RuleCondition::create('enabled', 'equals', true)->toArray()], [\PpPhp\Core\Platform\Rules\RuleAction::create('console_action', 'setDecision', ['decision' => 'allow'])->toArray()])->toArray()])); $result = $runtime->evaluate('console_rules', ['enabled' => true]); $this->line('Matched: ' . ($result->matched() ? 'YES' : 'NO')); $this->line('Actions: ' . count($result->actions()));
        return 0;
    }
}
