<?php
/**
 * Authorize.Net Helper methods.
 *
 * @package EverestForms\AuthorizeNet.
 *
 * @since 1.0.0
 */

namespace EverestForms\Pro\Addons\Mollie;

/**
 * Helper methods for Authorize.Net.
 *
 * @since 1.0.0
 */
class Helpers {

	/**
	 * Get Authorize.Net mode for payment.
	 *
	 * @return string
	 */
	public static function get_mollie_mode() {
		return 'yes' === get_option( 'everest_forms_mollie_test_mode' ) ? 'test' : 'live';
	}

	/**
	 * Get Authorize.Net API login ID.
	 *
	 * @return string
	 */
	public static function get_mollie_api_key() {

		$mode = self::get_mollie_mode();

		return sanitize_text_field( get_option( " everest_forms_mollie_{$mode}_api_key" ) );
	}

	/**
	 * Check the Mollie is enable or not, if enabled return true otherwise false.
	 *
	 * @param array $form_data Form data.
	 *
	 * @return bool
	 */
	public static function is_mollie_enabled( $form_data ) {
		$is_mollie_enabled        = isset( $form_data['payments']['mollie']['enable_mollie'] ) ? $form_data['payments']['mollie']['enable_mollie'] : '0';
		$is_paypal_enabled        = isset( $form_data['payments']['paypal']['enable_paypal'] ) ? $form_data['payments']['paypal']['enable_paypal'] : '0';
		$is_stripe_enabled        = isset( $form_data['payments']['stripe']['enable_stripe'] ) ? $form_data['payments']['stripe']['enable_stripe'] : '0';
		$is_authorize_net_enabled = isset( $form_data['payments']['authorize_net']['enable_authorize_net'] ) ? $form_data['payments']['authorize_net']['enable_authorize_net'] : '0';
		$is_razorpay_enabled      = isset( $form_data['payments']['razorpay']['enable_razorpay'] ) ? $form_data['payments']['razorpay']['enable_razorpay'] : '0';
		$is_square_enabled        = isset( $form_data['payments']['square']['enable_square'] ) ? $form_data['payments']['square']['enable_square'] : '0';

		if ( '1' === $is_mollie_enabled && '0' === $is_paypal_enabled && '0' === $is_stripe_enabled && '0' === $is_authorize_net_enabled && '0' === $is_razorpay_enabled && '0' === $is_square_enabled ) {
			return true;
		}

		return false;
	}

	/**
	 * Validates the API credentials.
	 *
	 * @return bool True if the API credentials are valid, false otherwise.
	 */
	public static function validate_api_credentials() {

		return ! empty( self::get_mollie_api_key() );
	}

	/**
	 * Retrieves the redirection url.
	 *
	 * @param array $form_data Form Data.
	 *
	 * @return string redirection url.
	 */
	public static function get_mollie_redirection_url( $form_data ) {
		return ! empty( $form_data['payments']['mollie']['redirect_url'] ) ? sanitize_text_field( $form_data['payments']['mollie']['redirect_url'] ) : home_url();
	}

	/**
	 * Retrieves the webhook url.
	 *
	 * @param array $form_data Form Data.
	 *
	 * @return string webhook url.
	 */
	public static function get_mollie_webhook_url( $form_data ) {
		return isset( $form_data['payments']['mollie']['webhook_url'] ) ? sanitize_text_field( $form_data['payments']['mollie']['webhook_url'] ) : '';
	}
}
