<?php
/**
 * AntiSpamProviderOption.php.
 *
 * @package RewardsWP
 * @since 1.2.0
 */

namespace Awesomemotive\Rewardswp\Settings\Options\General;

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

use Awesomemotive\Rewardswp\Abstracts\AbstractOption;
use Awesomemotive\Rewardswp\Interfaces\OptionInterface;

/**
 * Class AntiSpamProviderOption.
 *
 * Stores the selected anti-spam provider.
 *
 * @since 1.2.0
 */
class AntiSpamProviderOption extends AbstractOption implements OptionInterface {
	/**
	 * Get the setting key used in the option array.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_name(): string {
		return 'antispam_provider';
	}

	/**
	 * Get the setting group.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_group(): string {
		return 'general';
	}

	/**
	 * Get the default value for the setting.
	 *
	 * Defaults to honeypot as it's available for all plans.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_default_value(): string {
		return 'honeypot';
	}

	/**
	 * Get the label for the setting.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_label(): string {
		return esc_html__( 'Anti-Spam Protection', 'rewardswp' );
	}

	/**
	 * Get the type of the setting (text, textarea, select, etc).
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_type(): string {
		return 'select';
	}

	/**
	 * Get the available options.
	 *
	 * @since 1.2.0
	 *
	 * @return array
	 */
	public function get_options(): array {
		return [
			[
				'value' => 'honeypot',
				'label' => esc_html__( 'Honeypot (Invisible)', 'rewardswp' ),
			],
			// Future providers will be added here:
			// [
			//     'value' => 'google_recaptcha',
			//     'label' => esc_html__( 'Google reCAPTCHA v3', 'rewardswp' ),
			// ],
			// [
			//     'value' => 'hcaptcha',
			//     'label' => esc_html__( 'hCaptcha', 'rewardswp' ),
			// ],
			// [
			//     'value' => 'cloudflare_turnstile',
			//     'label' => esc_html__( 'Cloudflare Turnstile', 'rewardswp' ),
			// ],
		];
	}

	/**
	 * Sanitize the option value.
	 *
	 * @since 1.2.0
	 *
	 * @param mixed $value The value to sanitize.
	 *
	 * @return string
	 */
	public function sanitize( $value ): string {
		$valid_providers = array_column( $this->get_options(), 'value' );

		if ( in_array( $value, $valid_providers, true ) ) {
			return $value;
		}

		return $this->get_default_value();
	}
}

