<?php

namespace App\Domain\Setting\Infrastructure\Persistence\Mapper;

use App\Domain\Setting\Domain\Model\ContentSource;
use App\Entity\ContentSource as ContentSourceEntity;

readonly class ContentSourceMapper
{
    public function toDomain(ContentSourceEntity $entity): ContentSource
    {
        return new ContentSource(
            id: $entity->getId(),
            baseUrl: $entity->getBaseUrl(),
            chapterUrlFormat: $entity->getChapterUrlFormat(),
            scrapingType: $entity->getScrapingType(),
            imageSelector: $entity->getImageSelector(),
            nextPageSelector: $entity->getNextPageSelector(),
            chapterSelector: $entity->getChapterSelector(),
            testSlug: $entity->getTestSlug(),
            testChapterNumber: $entity->getTestChapterNumber(),
            healthStatus: $entity->getHealthStatus(),
            healthLastTestedAt: $entity->getHealthLastTestedAt(),
            healthLastError: $entity->getHealthLastError(),
        );
    }

    public function toEntity(ContentSource $contentSource): ContentSourceEntity
    {
        $entity = new ContentSourceEntity();

        $entity->setBaseUrl($contentSource->getBaseUrl())
               ->setChapterUrlFormat($contentSource->getChapterUrlFormat())
               ->setScrapingType($contentSource->getScrapingType())
               ->setImageSelector($contentSource->getImageSelector())
               ->setNextPageSelector($contentSource->getNextPageSelector())
               ->setChapterSelector($contentSource->getChapterSelector())
               ->setTestSlug($contentSource->getTestSlug())
               ->setTestChapterNumber($contentSource->getTestChapterNumber())
               ->setHealthStatus($contentSource->getHealthStatus())
               ->setHealthLastTestedAt($contentSource->getHealthLastTestedAt())
               ->setHealthLastError($contentSource->getHealthLastError());

        return $entity;
    }

    public function updateEntity(ContentSourceEntity $entity, ContentSource $contentSource): ContentSourceEntity
    {
        $entity->setBaseUrl($contentSource->getBaseUrl())
               ->setChapterUrlFormat($contentSource->getChapterUrlFormat())
               ->setScrapingType($contentSource->getScrapingType())
               ->setImageSelector($contentSource->getImageSelector())
               ->setNextPageSelector($contentSource->getNextPageSelector())
               ->setChapterSelector($contentSource->getChapterSelector())
               ->setTestSlug($contentSource->getTestSlug())
               ->setTestChapterNumber($contentSource->getTestChapterNumber())
               ->setHealthStatus($contentSource->getHealthStatus())
               ->setHealthLastTestedAt($contentSource->getHealthLastTestedAt())
               ->setHealthLastError($contentSource->getHealthLastError());

        return $entity;
    }
}
