<?php
namespace SabaiApps\Directories\Component\Payment\Component;

use SabaiApps\Directories\Application;
use SabaiApps\Directories\Component\Entity\Type\IEntity;
use SabaiApps\Directories\Component\Payment\IOrder;
use SabaiApps\Directories\Component\Payment\ISubscription;
use SabaiApps\Directories\Context;

abstract class AbstractComponent implements IComponent {

	protected $_application, $_name, $_info;

	public function __construct( Application $application, $name ) {
		$this->_application = $application;
		$this->_name        = $name;
	}

	public function paymentComponentName() {
		return $this->_name;
	}

	public function paymentComponentInfo( $key = null ) {
		if ( ! isset( $this->_info ) ) {
			$this->_info = (array) $this->_paymentComponentInfo();
		}

		return isset( $key ) ? ( isset( $this->_info[ $key ] ) ? $this->_info[ $key ] : null ) : $this->_info;
	}

	public function paymentCheckoutForm( Context $context, $planOrOrder, ?IEntity $entity = null, $action = null ) {
		return array();
	}

	public function paymentCheckoutBtnText( $bundleName, $action, $planId = null ) {}

	public function getSettings() {
		return $this->_application->getComponent( 'Payment' )->getConfig( 'payment', 'components', $this->_name );
	}

	abstract protected function _paymentComponentInfo();

	public function paymentIsOrderCancellable() {
		return false;
	}

	public function paymentCancelOrder( IOrder $order, $isManual = false ) {}

	public function paymentIsSubscriptionCancellable() {
		return false;
	}

	public function paymentCancelSubscription( ISubscription $subscription, $isManual = false ) {}
}
