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

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

abstract class AbstractFeature implements IFeature {

	protected $_application, $_name;

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

	abstract protected function _entityFeatureInfo();

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

	public function entityFeatureDefaultSettings( Bundle $bundle ) {
		return false; // use default_settings in info array
	}

	public function entityFeatureSupports( Bundle $bundle ) {
		return true;
	}

	public function entityFeatureSettingsForm( Bundle $bundle, array $settings, array $parents = array() ) {}

	public function entityFeatureIsEnabled( Bundle $bundle, array $settings ) {
		return true;
	}

	public function entityFeatureOnEntityForm( Bundle $bundle, array $settings, array &$form, ?IEntity $entity = null, $isAdmin = false ) {}

	public function entityFeatureOnEntityFieldValues( IEntity $entity, Bundle $bundle, array $settings ) {}

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