<?php

if (!defined('ABSPATH')) {
    exit;
}

/**
 * Class TamRank_Features
 * 
 * Central registry for feature flags.
 * Determines if a feature should be loaded based on user settings.
 */
class TamRank_Features
{
    /**
     * Default state for features
     * @var array
     */
    private static $defaults = [
        'enable_meta_boxes' => true,
        'enable_404_monitoring' => true,
        'enable_seo_audit' => true,
        'enable_redirects' => true,
        'enable_change_tracking' => true,
        'enable_auto_redirect_on_delete' => true,
        'delete_all_data_on_uninstall' => false,
    ];

    /**
     * Cached settings
     * @var array|null
     */
    private static $settings = null;

    /**
     * Check if a feature is enabled
     * 
     * @param string $feature Feature key (e.g. 'seo_audit' or 'enable_seo_audit')
     * @return bool
     */
    public static function is_enabled($feature)
    {
        // Normalize key (allow calling with or without 'enable_' prefix)
        $key = (strpos($feature, 'enable_') === 0) ? $feature : 'enable_' . $feature;

        // Load settings once
        if (self::$settings === null) {
            self::$settings = get_option('tam_rank_general_settings', []);
        }

        // Return setting value or default
        if (isset(self::$settings[$key])) {
            return (bool) self::$settings[$key];
        }

        return isset(self::$defaults[$key]) ? self::$defaults[$key] : false;
    }


    /**
     * Get default feature states
     * @return array
     */
    public static function get_defaults()
    {
        return self::$defaults;
    }
}
