<?php

namespace MPHB\Payments\Gateways;

use MPHB\Entities\{ Booking, Payment };

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

class TestGateway extends Gateway {
	public const GATEWAY_ID = 'test';

	public function __construct() {
		parent::__construct();

		add_filter(
			'mphb_gateway_has_sandbox',
			function( bool $isShow, string $gatewayId ) {
				return $gatewayId === $this->getId() ? false : $isShow;
			},
			10,
			2
		);
	}

	/**
	 * @return string
	 */
	public function getMode() {
		return static::MODE_LIVE;
	}

	/**
	 * @return bool
	 */
	public function isSandbox() {
		return false;
	}

	protected function isPaymentFeeSupported(): bool {
		return true;
	}

	protected function setupProperties() {
		parent::setupProperties();

		$this->adminTitle = __( 'Test Payment', 'motopress-hotel-booking' );
	}

	protected function initDefaultOptions() {
		$defaults = array(
			'title'       => __( 'Test Payment', 'motopress-hotel-booking' ),
			'description' => '',
			'enabled'     => false,
		);

		return array_merge( parent::initDefaultOptions(), $defaults );
	}

	/**
	 * @return mixed|null
	 */
	public function processPayment( Booking $booking, Payment $payment ) {
		$isCompleted = $this->paymentCompleted( $payment );

		if ( ! $isCompleted ) {
			wp_redirect( MPHB()->settings()->pages()->getPaymentFailedPageUrl( $payment ) );
		}
	}
}
