<?php

namespace App\Domain\Manga\Domain\Model;

use App\Domain\Manga\Domain\Model\ValueObject\ChapterId;

readonly class Chapter
{
    public function __construct(
        private ChapterId $id,
        private string $mangaId,
        private float $number,
        private ?string $title,
        private ?int $volume,
        private bool $isVisible,
        private ?string $cbzPath = null,
        private \DateTimeImmutable $createdAt = new \DateTimeImmutable()
    ) {}

    public function getId(): string
    {
        return $this->id->getValue();
    }

    public function getMangaId(): string
    {
        return $this->mangaId;
    }

    public function getNumber(): float
    {
        return $this->number;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function getVolume(): ?int
    {
        return $this->volume;
    }

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

    public function isAvailable(): bool
    {
        return $this->cbzPath !== null;
    }

    public function getCbzPath(): ?string
    {
        return $this->cbzPath;
    }

    public function getCreatedAt(): \DateTimeImmutable
    {
        return $this->createdAt;
    }

    public function updateTitle(?string $title): self
    {
        return new self(
            $this->id,
            $this->mangaId,
            $this->number,
            $title,
            $this->volume,
            $this->isVisible,
            $this->cbzPath,
            $this->createdAt
        );
    }

    public function updateVolume(?int $volume): self
    {
        return new self(
            $this->id,
            $this->mangaId,
            $this->number,
            $this->title,
            $volume,
            $this->isVisible,
            $this->cbzPath,
            $this->createdAt
        );
    }
}
