<?php

namespace App\Domain\Manga\Domain\Model;

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

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

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

    public function getMangaId(): MangaId
    {
        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->pagesDirectory !== null;
    }

    public function getPagesDirectory(): ?string
    {
        return $this->pagesDirectory;
    }

    public function getPageCount(): int
    {
        return $this->pageCount;
    }

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

    public function updateTitle(?string $title): void
    {
        $this->title = $title;
    }

    public function updateVolume(?int $volume): void
    {
        $this->volume = $volume;
    }

    public function updatePagesDirectory(?string $pagesDirectory, int $pageCount = 0): void
    {
        $this->pagesDirectory = $pagesDirectory;
        $this->pageCount = $pageCount;
    }

    public function hide(): void
    {
        $this->isVisible = false;
    }
}
