<?php

namespace SugarCalendarBookings\Antispam\Captcha;

/**
 * Google reCAPTCHA v2 verifier (checkbox + invisible variants).
 *
 * @since 1.5.0
 */
class RecaptchaV2 extends AbstractCaptchaVerifier {

	public const CATEGORY                = 'recaptcha';
	public const ENDPOINT_URL            = 'https://www.google.com/recaptcha/api/siteverify';
	public const SECRET_OPTION_KEY       = 'antispam.recaptcha_v2.secret_key';
	public const SECRET_FILTER_NAME      = 'sugar_calendar_bookings_antispam_recaptcha_v2_secret_key';
	public const SITE_KEY_OPTION_KEY     = 'antispam.recaptcha_v2.site_key';
	public const THEME_OPTION_KEY        = 'antispam.recaptcha.theme';
	public const FAIL_MESSAGE_OPTION_KEY = 'antispam.recaptcha.fail_message';

	public const SCRIPT_HANDLE  = 'scbookings-booking-form-google-recaptcha';
	public const SCRIPT_API_URL = 'https://www.google.com/recaptcha/api.js';
	public const CONFLICT_HOSTS = [
		'google.com/recaptcha',
		'gstatic.com/recaptcha',
	];

	public const TEST_KEY_HOSTNAME = 'testkey.google.com';

	/**
	 * Frontend config for the localized booking-form payload.
	 *
	 * @since 1.5.0
	 *
	 * @return array
	 */
	public function get_frontend_config(): array {

		return [
			'site_key' => $this->get_site_key(),
			'theme'    => $this->get_theme(),
		];
	}

	/**
	 * Default fail message for reCAPTCHA v2.
	 *
	 * @since 1.5.0
	 *
	 * @return string
	 */
	public function get_fail_message_default(): string {

		return esc_html__( 'reCAPTCHA verification failed, please try again.', 'sugar-calendar-bookings-scheduling-appointments-lite' );
	}
}
