<?php
/**
 * Allowlist Controller
 * 
 * Handles all allowlist checks (WAF parameters, IPs, Services).
 * Phase 1: WAF Parameter Allowlist only.
 * Phase 2: IP and Service Allowlist will be added later.
 *
 * @package VMPFence
 * @subpackage Firewall\Controllers
 */

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

class VMPFence_Allowlist_Controller {
    
    /**
     * Main entry point - check if request is allowlisted
     * 
     * Phase 1: Only WAF parameter checks
     * Phase 2: Will add IP and Service checks
     *
     * @param VMPFence_Request $request Request object
     * @return bool True if allowlisted
     */
    public static function is_allowlisted($request) {
        // Phase 2: IP allowlist check will go here (check FIRST, before all other checks)
        // Phase 2: Service allowlist check will go here (Google/Bing/Yahoo)
        
        // Phase 1: WAF parameter allowlist is checked during WAF rule evaluation
        // This method will be expanded in Phase 2
        
        return false;
    }
    
    /**
     * Check if a parameter is allowlisted for a specific WAF rule
     * 
     * Called from WAF controller during rule evaluation loop.
     *
     * @param string $rule_id WAF rule ID
     * @param string $path URL path
     * @param string $param_key Parameter name
     * @return bool True if allowlisted
     */
    public static function check_param_allowlist($rule_id, $path, $param_key) {        
        // Delegate to model
        return VMPFence_Param_Allowlist::is_rule_param_allowlisted($rule_id, $path, $param_key);
    }
    
    /**
     * Get allowlist statistics for admin dashboard
     *
     * @return array Statistics array
     */
    public static function get_allowlist_stats() {
        $stats = array(
            'param_allowlist_count' => 0,
            'ip_allowlist_count' => 0,
            'service_allowlist_count' => 0
        );
        
        // Get WAF parameter allowlist count
        $params = VMPFence_Param_Allowlist::get_all_allowlisted_params();
        $stats['param_allowlist_count'] = count($params);
        
        // Phase 2: Add IP and Service counts
        
        return $stats;
    }
}
