<?php

declare(strict_types=1);

namespace App\Domain\Shared\Domain\Model;

readonly class FileMetadata
{
    public function __construct(
        public string $title,
        public ?int $volume = null,
        public ?int $chapter = null,
        public ?string $author = null,
        public ?string $description = null,
        public array $additionalData = []
    ) {
    }

    public static function fromArray(array $data): self
    {
        return new self(
            title: $data['title'] ?? '',
            volume: $data['volume'] ?? null,
            chapter: $data['chapter'] ?? null,
            author: $data['author'] ?? null,
            description: $data['description'] ?? null,
            additionalData: $data['additionalData'] ?? []
        );
    }

    public function toArray(): array
    {
        return [
            'title' => $this->title,
            'volume' => $this->volume,
            'chapter' => $this->chapter,
            'author' => $this->author,
            'description' => $this->description,
            'additionalData' => $this->additionalData,
        ];
    }
}
