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

use SabaiApps\Directories\Application;
use SabaiApps\Directories\Component\Entity\Type\IEntity;

abstract class AbstractFeature implements IFeature {

	use DefaultTrait;

	protected $_application, $_name;

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

	abstract protected function _paymentFeatureInfo();

	public function paymentFeatureInfo( $key = null ) {
		$info = $this->_paymentFeatureInfo();
		return isset( $key ) ? ( isset( $info[ $key ] ) ? $info[ $key ] : null ) : $info;
	}

	protected function _maxNumAllowedLabel( $label ) {
		return sprintf( __( 'Max number of %s allowed', 'directories-pro' ), strtolower( $label ), $label );
	}

	protected function _additionalNumAllowedLabel( $label ) {
		return sprintf( __( 'Additional number of %s allowed', 'directories-pro' ), strtolower( $label ), $label );
	}

	protected function _applyAddonFeature( IEntity $entity, $featureName, array $featureSettings, array &$values, $orderId, $isMultiple = false ) {
		return call_user_func_array(
			array( $this->_application, 'Payment_Features_applyAddonFeature' ),
			array( $entity, $featureName, $featureSettings, &$values, $orderId, $isMultiple )
		);
	}

	protected function _unapplyAddonFeature( IEntity $entity, $featureName, array $featureSettings, array &$values, $orderId, $isMultiple = false ) {
		return call_user_func_array(
			array( $this->_application, 'Payment_Features_unapplyAddonFeature' ),
			array( $entity, $featureName, $featureSettings, &$values, $orderId, $isMultiple )
		);
	}
}
