<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Workflow\Bpmn;

final class BpmnRuntimeSnapshot
{
    public function __construct(
        private readonly array $models = [],
        private readonly array $designerModels = [],
        private readonly array $imports = [],
        private readonly array $exports = [],
        private readonly array $statistics = [],
        private readonly string $createdAt = ''
    ) {}

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

    public function models(): array { return $this->models; }
    public function designerModels(): array { return $this->designerModels; }
    public function imports(): array { return $this->imports; }
    public function exports(): array { return $this->exports; }
    public function statistics(): array { return $this->statistics; }

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