<?php
declare(strict_types=1);

namespace Ekesto\CacheInvalidator\Integrations\Structural\Core;

/**
 * Shared classification helpers for core structural entities.
 */
final class CoreStructuralEntityClassifier
{
    /**
     * Determine whether a wp_block post represents a synced pattern.
     *
     * @param \WP_Post $post Post object.
     * @return bool
     */
    public static function isSyncedPattern(\WP_Post $post): bool
    {
        if ($post->post_type !== 'wp_block') {
            return false;
        }

        $syncStatus = strtolower((string) get_post_meta((int) $post->ID, 'wp_pattern_sync_status', true));
        $isSynced = !in_array($syncStatus, ['unsynced', '0', 'false'], true);

        /**
         * Filter synced-pattern detection for wp_block posts.
         *
         * @param bool     $isSynced Synced state.
         * @param \WP_Post $post Post object.
         */
        return (bool) apply_filters('ekesto_ci_is_synced_pattern', $isSynced, $post);
    }
}
