<?php

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound -- APD is the established namespace shared with the Pro add-on and retained for backward compatibility.
namespace APD\Meta;

use APD\Support\ConfigMetaSanitizer;

defined('ABSPATH') || exit;

class ProductConfigMeta
{
    public function register() : void
    {
        $keys = [
            '_apd_theme',
            '_apd_layout',
            '_apd_modules',
            '_apd_permissions',
            '_apd_views',
            '_apd_drawing_zones',
            '_apd_fonts',
            '_apd_upload',
            '_apd_colors',
            '_apd_pricing_rules',
            '_apd_pricing_rule_ids',
            '_apd_mode',
            '_apd_selection_menu',
            '_apd_ui',
            '_apd_front_behavior',
            '_apd_mobile_behavior',
            '_apd_initial_document',
            '_apd_initial_state',
            '_apd_asset_filters',
            '_apd_template_id',
        ];

        foreach ($keys as $key) {
            register_post_meta('apd_product_config', $key, [
                'show_in_rest' => false,
                'single' => true,
                'type' => 'string',
                'sanitize_callback' => static function ($value, string $metaKey) {
                    return ConfigMetaSanitizer::sanitize($metaKey, $value);
                },
                'auth_callback' => static function () {
                    return current_user_can('edit_asuka_product_configs');
                },
                'default' => '',
            ]);
        }
    }
}
