<?php
declare(strict_types=1);

namespace Ekesto\CacheInvalidator\Resolvers;

use Ekesto\CacheInvalidator\Core\Relationships\RelationshipProviderRegistry;
use Ekesto\CacheInvalidator\Support\Debug;

/**
 * Lite-safe facade for host-post resolution.
 *
 * Preserves the public static signature for existing call sites and delegates to
 * the registered relationship provider, which is a Lite-safe no-op unless the
 * premium relationship implementation is present. The Pro-only
 * `ekesto_ci_relationship_meta_keys` filter is never applied in this file.
 */
final class RelationshipResolver
{
    /**
     * Find host post IDs that reference a given related post.
     *
     * @param string $hostPostType    The post type to search (e.g. 'event').
     * @param string $relatedPostType The post type of the changed entity (e.g. 'speaker').
     * @param int    $relatedId       The ID of the changed related post.
     * @return int[] Array of host post IDs.
     */
    public static function findHostPostIds(string $hostPostType, string $relatedPostType, int $relatedId): array
    {
        try {
            return RelationshipProviderRegistry::current()->findHostPostIds($hostPostType, $relatedPostType, $relatedId);
        } catch (\Throwable $throwable) {
            Debug::log('relationship_provider_error', [
                'method' => 'findHostPostIds',
                'error' => $throwable->getMessage(),
            ]);
            return [];
        }
    }
}
