<?php
/**
 * Cache-Safe Mode detection engine (runs inside an AJAX handler).
 *
 * Returns structured arrays instead of calling wp_die() directly, so the
 * client-side JS can render the blocked page.
 *
 * BUG 11 FIX: ~300 lines of duplication removed (logic lives in FENSE_BPVT_RUN_BASE).
 *
 * @package FENSE_BPVT
 */

if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

class FENSE_BPVT_RUN_SAVE_MODE extends FENSE_BPVT_RUN_BASE
{
	
	/**
	 * Checks admin/logged-in status.
	 * Uses current_user_can() since is_admin() is unreliable inside AJAX.
	 */
	public function isAdminOrLoggedIn(): bool
	{
		return current_user_can( 'manage_options' ) || is_user_logged_in();
	}
	
	/**
	 * Returns ['stop'=>bool, 'isProxy'=>bool] from the current country rules.
	 */
	public function getCountryResult(): array
	{
		$c = $this->evaluateCountry();
		
		return [
			'exclude' => $c['exclude'],
			'ignoreProxy' => $c['ignoreProxy'],
		];
	}
	
	/**
	 * Evaluates the protection mode and returns a status array.
	 * Returns ['status'=>bool, 'message'=>string, 'disable_link'=>string, 'link'=>string].
	 */
	public function getProtectionResult(): array
	{
		if ( !$this->isProxy() ) {
			return [ 'status' => false ];
		}
		FENSE_BPVT_FUN::cleanUP();
		return [
			'message' => $this->settings->message,
			'disable_link' => $this->settings->disable_link,
			'link' => $this->settings->link,
		];
	}
}
