<?php

namespace WPSN\Domain;

defined('ABSPATH') || exit;

final class SeoDocumentContext
{
    public const TYPE_SINGULAR = 'singular';
    public const TYPE_TERM     = 'term';
    public const TYPE_HOME     = 'home';
    public const TYPE_SEARCH   = 'search';
    public const TYPE_ARCHIVE  = 'archive';
    public const TYPE_404      = '404';

    public string $type;

    /** post ID or term ID where applicable */
    public ?int $objectId;

    /** post_type or taxonomy where applicable */
    public ?string $objectSubType;

    public string $url;

    public int $paged;

    public function __construct(string $type, ?int $objectId, ?string $objectSubType, string $url, int $paged = 1)
    {
        $this->type          = $type;
        $this->objectId      = $objectId;
        $this->objectSubType = $objectSubType;
        $this->url           = $url;
        $this->paged         = max(1, (int) $paged);
    }

    public function isPaged(): bool
    {
        return $this->paged > 1;
    }

    public function isSingular(): bool
    {
        return $this->type === self::TYPE_SINGULAR && $this->objectId !== null;
    }

    public function isTerm(): bool
    {
        return $this->type === self::TYPE_TERM && $this->objectId !== null;
    }
}
