<?php

namespace App\Domain\Scraping\Domain\Model;

use App\Domain\Scraping\Domain\Model\ValueObject\ChapterUrl;
use App\Domain\Scraping\Domain\Model\ValueObject\SourceId;
use DateTimeImmutable;

readonly class Source
{
    public function __construct(
        private SourceId            $id,
        private string            $name,
        private string            $description,
        private string            $baseUrl,
        private array             $scrappingParameters,
        private bool              $isActive,
        private DateTimeImmutable $createdAt,
        private DateTimeImmutable $updatedAt
    ) {
    }

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

    public function getName(): string
    {
        return $this->name;
    }

    public function getDescription(): string
    {
        return $this->description;
    }

    public function getBaseUrl(): string
    {
        return $this->baseUrl;
    }

    public function getScrappingParameters(): array
    {
        return $this->scrappingParameters;
    }

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

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

    public function getUpdatedAt(): DateTimeImmutable
    {
        return $this->updatedAt;
    }

    public function buildChapterUrl(string $mangaSlug, float $chapterNumber): string
    {
        $chapterUrl = new ChapterUrl($this->scrappingParameters['chapterUrlFormat'], $mangaSlug, $chapterNumber);
        return $chapterUrl->getUrl();
    }
}
