<?php
declare(strict_types=1);

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

final class EventCompactionPolicy
{
    public function __construct(
        private readonly int $retainLastEvents = 2,
        private readonly bool $snapshotSafe = true,
        private readonly bool $archiveCompacted = true
    ) {}

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

    public function snapshotSafe(): bool
    {
        return $this->snapshotSafe;
    }

    public function archiveCompacted(): bool
    {
        return $this->archiveCompacted;
    }

    public function toArray(): array
    {
        return [
            'retainLastEvents' => $this->retainLastEvents(),
            'snapshotSafe' => $this->snapshotSafe(),
            'archiveCompacted' => $this->archiveCompacted(),
        ];
    }
}
