<?php
declare(strict_types=1);

namespace Ekesto\CacheWarmup\Core;

/**
 * Central trigger label lookup for post-type-driven run labels.
 */
final class TriggerLabelMap
{
    /**
     * Resolve a human-readable label for a post type.
     *
     * @param string|null $postType Canonical post type key.
     * @return string|null
     */
    public static function forPostType(?string $postType): ?string
    {
        $postType = sanitize_key((string) $postType);
        if ($postType === '') {
            return null;
        }

        $map = [
            // Core
            'post' => 'Post update',
            'page' => 'Page update',

            // WooCommerce
            'product' => 'Product update',

            // Elementor
            'elementor_component' => 'Component update',
            'elementor_library' => 'Template update',

            // Core structural
            'wp_template' => 'Template update',
            'wp_template_part' => 'Template part update',
            'wp_block' => 'Synced pattern update',
            'wp_navigation' => 'Navigation update',
        ];

        /**
         * Allow extension for custom post types.
         *
         * @param array<string,string> $map
         */
        $map = apply_filters('ekesto_cw_trigger_label_map', $map);

        if (!is_array($map)) {
            return null;
        }

        $label = $map[$postType] ?? null;
        return is_string($label) && $label !== '' ? $label : null;
    }
}
