<?php
declare(strict_types=1);

namespace ROITheme\Shared\Infrastructure\Services;

use ROITheme\Shared\Domain\Contracts\PageTypeDetectorInterface;
use ROITheme\Shared\Domain\ValueObjects\PageType;

/**
 * Implementación WordPress del detector de tipo de página
 *
 * @package ROITheme\Shared\Infrastructure\Services
 */
final class WordPressPageTypeDetector implements PageTypeDetectorInterface
{
    public function detect(): PageType
    {
        if ($this->isHome()) {
            return PageType::home();
        }

        if ($this->isPost()) {
            return PageType::post();
        }

        if ($this->isPage()) {
            return PageType::page();
        }

        if ($this->isSearch()) {
            return PageType::search();
        }

        if ($this->isArchive()) {
            return PageType::archive();
        }

        return PageType::fromString(PageType::UNKNOWN);
    }

    public function isHome(): bool
    {
        return is_front_page();
    }

    public function isPost(): bool
    {
        return is_single() && !is_front_page();
    }

    public function isPage(): bool
    {
        return is_page() && !is_front_page();
    }

    public function isArchive(): bool
    {
        return is_archive();
    }

    public function isSearch(): bool
    {
        return is_search();
    }
}
