<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Workflow\HumanTask;

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

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

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

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