<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;

final class SnapshotCreateCommand extends AbstractCommand
{
    public function name(): string { return 'snapshot:create'; }
    public function description(): string { return 'PPphp Snapshot Create'; }

    public function handle(array $arguments = []): int
    {
        $this->title('PPphp Snapshot Create');
        $base = \PpPhp\Core\Platform\Console\ConsolePath::basePath(); $aggregate = \PpPhp\Core\Platform\Event\Sourcing\Aggregate\AggregateRepositoryRuntime::instance($base)->load('console-aggregate'); if ($aggregate->version() === 0) { $aggregate = \PpPhp\Core\Platform\Event\Sourcing\Aggregate\AggregateRepositoryRuntime::instance($base)->save('console-aggregate', 'ConsoleAggregate', 'ConsoleSnapshotSeeded', ['seeded' => true]); } $snapshot = \PpPhp\Core\Platform\Event\Sourcing\Snapshot\SnapshotRuntime::instance($base)->create($aggregate, ['source' => 'console']); $this->line('Created: YES'); $this->line('Snapshot: ' . $snapshot->snapshotId()); $this->line('Version: ' . $snapshot->version());
        return 0;
    }
}
