<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Sourcing\Snapshot;

final class SnapshotPolicy
{
    public function __construct(private readonly int $frequency = 2) {}

    public function frequency(): int
    {
        return max(1, $this->frequency);
    }

    public function shouldSnapshot(int $version): bool
    {
        return $version > 0 && ($version % $this->frequency()) === 0;
    }

    public function toArray(): array
    {
        return ['frequency' => $this->frequency()];
    }
}
