<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;
use PpPhp\Core\Platform\Console\ConsolePath;
use PpPhp\Core\Platform\Event\Verification\EventCoreLock;
use PpPhp\Core\Platform\Event\Verification\EventVerificationService;

final class EventsLockCommand extends AbstractCommand
{
    public function name(): string { return 'events:lock'; }
    public function description(): string { return 'Verify and lock Event Core subsystem.'; }

    public function handle(array $arguments = []): int
    {
        $service = new EventVerificationService();
        $status = $service->lock(ConsolePath::basePath());

        $this->title('PPphp Event Core Lock');
        $this->line('Status: ' . ($status->ok() ? 'LOCKED' : 'FAILED'));
        $this->line('Score: ' . ($status->summary()['score'] ?? 0) . '%');
        $this->line('Report: ' . EventVerificationService::REPORT_FILE);
        $this->line('File: ' . EventCoreLock::LOCK_FILE);

        return $status->ok() ? 0 : 1;
    }
}
