<?php

namespace App\Domain\Setting\Application\Response;

use App\Domain\Setting\Domain\Model\ContentSource;

readonly class ContentSourceResponse
{
    public function __construct(
        public int $id,
        public string $baseUrl,
        public string $chapterUrlFormat,
        public string $scrapingType,
        public ?string $imageSelector,
        public ?string $nextPageSelector,
        public ?string $chapterSelector,
        public string $cleanBaseUrl,
        public ?string $testSlug = null,
        public ?float $testChapterNumber = null,
        public string $healthStatus = 'unknown',
        public ?\DateTimeImmutable $healthLastTestedAt = null,
        public ?string $healthLastError = null,
    ) {
    }

    public static function fromDomain(ContentSource $contentSource): self
    {
        return new self(
            id: $contentSource->getId(),
            baseUrl: $contentSource->getBaseUrl(),
            chapterUrlFormat: $contentSource->getChapterUrlFormat(),
            scrapingType: $contentSource->getScrapingType(),
            imageSelector: $contentSource->getImageSelector(),
            nextPageSelector: $contentSource->getNextPageSelector(),
            chapterSelector: $contentSource->getChapterSelector(),
            cleanBaseUrl: $contentSource->getCleanBaseUrl(),
            testSlug: $contentSource->getTestSlug(),
            testChapterNumber: $contentSource->getTestChapterNumber(),
            healthStatus: $contentSource->getHealthStatus(),
            healthLastTestedAt: $contentSource->getHealthLastTestedAt(),
            healthLastError: $contentSource->getHealthLastError(),
        );
    }
}
