<?php
/**
 * Block Exception
 *
 * @package VMPFence
 * @since 2.0.0
 * @since 2.2.5 Added silent flag to suppress event logging for already-blocked IPs
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Exception thrown when a request should be blocked
 */
class VMPFence_Block_Exception extends VMPFence_Firewall_Exception {
    
    /**
     * Total violation score
     *
     * @var int
     */
    protected $score = 0;
    
    /**
     * Block type (e.g., 'rate_limit', 'waf', 'brute_force')
     *
     * @var string
     */
    protected $block_type = 'generic';
    
    /**
     * Additional block data
     *
     * @var array
     */
    protected $block_data = array();
    
    /**
     * Silent flag — when true, skip event logging (e.g., already-blocked IPs)
     *
     * @var bool
     * @since 2.2.4
     */
    protected $silent = false;
    
    /**
     * Constructor
     *
     * @param string $message Exception message
     * @param int $code Exception code
     * @param Exception $previous Previous exception
     */
    public function __construct($message = 'Request blocked', $code = 0, Exception $previous = null) {
        parent::__construct($message, $code, $previous);
    }
    
    /**
     * Set violation score
     *
     * @param int $score Total score
     */
    public function set_score($score) {
        $this->score = $score;
    }
    
    /**
     * Get violation score
     *
     * @return int
     */
    public function get_score() {
        return $this->score;
    }
    
    /**
     * Set block type
     *
     * @param string $type Block type
     */
    public function set_block_type($type) {
        $this->block_type = $type;
    }
    
    /**
     * Get block type
     *
     * @return string
     */
    public function get_block_type() {
        return $this->block_type;
    }
    
    /**
     * Set block data
     *
     * @param array $data Block data
     */
    public function set_block_data($data) {
        $this->block_data = $data;
    }
    
    /**
     * Get block data
     *
     * @return array
     */
    public function get_block_data() {
        return $this->block_data;
    }
    
    /**
     * Set silent flag
     *
     * @param bool $silent Whether to suppress event logging
     * @since 2.2.5
     */
    public function set_silent($silent) {
        $this->silent = (bool) $silent;
    }
    
    /**
     * Check if this exception is silent
     *
     * @return bool
     * @since 2.2.5
     */
    public function is_silent() {
        return $this->silent;
    }
}
