<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Rules\Repository;

final class RuleRepositorySnapshot
{
    public function __construct(
        private readonly array $entries = [],
        private readonly array $statistics = [],
        private readonly string $createdAt = ''
    ) {}

    public static function fromArray(array $data): self
    {
        return new self(
            (array) ($data['entries'] ?? []),
            (array) ($data['statistics'] ?? []),
            (string) ($data['createdAt'] ?? '')
        );
    }

    public function entries(): array { return $this->entries; }
    public function statistics(): array { return $this->statistics; }

    public function toArray(): array
    {
        return [
            'entries' => $this->entries,
            'statistics' => $this->statistics,
            'createdAt' => $this->createdAt !== '' ? $this->createdAt : date('c'),
        ];
    }
}
