<?php
declare(strict_types=1);

namespace Ekesto\CacheInvalidator\Integrations\Structural\Core;

/**
 * Value object describing one structural container reference.
 */
final class StructuralContainerReference
{
    private int $postId;

    private string $postType;

    /**
     * Build a structural container reference.
     *
     * @param int    $postId Post ID.
     * @param string $postType Post type key.
     */
    public function __construct(int $postId, string $postType)
    {
        $this->postId = absint($postId);
        $this->postType = sanitize_key($postType);
    }

    /**
     * Return the referenced post ID.
     *
     * @return int
     */
    public function postId(): int
    {
        return $this->postId;
    }

    /**
     * Return the referenced post type.
     *
     * @return string
     */
    public function postType(): string
    {
        return $this->postType;
    }

    /**
     * Return the canonical identity key.
     *
     * @return string
     */
    public function canonicalKey(): string
    {
        return $this->postType . ':' . $this->postId;
    }
}
