<?php
/**
 * @package Hafenstudios\Wellenbrecher
 */

namespace Hafenstudios\Wellenbrecher\Rules;

use Hafenstudios\Wellenbrecher\Engine\Context;
use Hafenstudios\Wellenbrecher\Engine\RuleResult;

defined( 'ABSPATH' ) || exit;

/**
 * POST ohne Accept-Language-Header: jeder echte Browser sendet ihn,
 * viele Bot-Bibliotheken nicht (sehr starkes, billiges Signal).
 */
class AcceptLanguageRule extends AbstractRule {

	public const ID             = 'no_accept_language';
	public const DEFAULT_POINTS = 15;

	public function __construct( int $points = self::DEFAULT_POINTS ) {
		parent::__construct( $points );
	}

	public function id(): string {
		return self::ID;
	}

	public function stage(): int {
		return 1;
	}

	public function evaluate( Context $context ): RuleResult {
		return '' === trim( $context->server( 'accept_language' ) ) ? $this->hit() : $this->miss();
	}
}
