<?php

namespace SugarCalendarBookings\Payments\Gateways\Onsite;

use SugarCalendarBookings\Options;
use SugarCalendarBookings\Payments\Gateways\AbstractPaymentGateway;
use SugarCalendarBookings\Plugin;

/**
 * On-site payment gateway.
 *
 * Implementation of payment operations for on-site payments.
 *
 * @since 1.0.0
 */
class OnSitePaymentGateway extends AbstractPaymentGateway {

	/**
	 * Gateway ID.
	 *
	 * @since 1.0.0
	 *
	 * @var string
	 */
	const ID = 'onsite';

	/**
	 * Get gateway name.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public static function get_name() {

		return __( 'On Site', 'sugar-calendar-bookings-scheduling-appointments-lite' );
	}

	/**
	 * Whether gateway is configured.
	 *
	 * Overrides the abstract default (which returns true unconditionally) so
	 * the admin's `payments.gateways.onsite.enabled` toggle actually gates
	 * authorize-time access. Without this, a visitor could swap a paid
	 * Stripe-only booking to the zero-charge On-Site processor regardless
	 * of the admin's enable setting — the request validator's "configured"
	 * filter is what `payments_authorize` checks against.
	 *
	 * @since 1.4.1
	 *
	 * @return bool
	 */
	public function is_configured() {

		return (bool) Plugin::get( Options::class )->get( 'payments.gateways.onsite.enabled' );
	}

	/**
	 * Get payment processor instance.
	 *
	 * @since 1.0.0
	 *
	 * @return OnSitePaymentProcessor
	 */
	public function get_processor() {

		return Plugin::get( OnSitePaymentProcessor::class );
	}
}
