<?php
namespace App\OfferProfileRules;

class Criterion_FirstCustomerType extends CriterionAbstract
{

	/**
	 *
	 * {@inheritDoc}
	 * @see \App\OfferProfileRules\CriterionAbstract::checkFields()
	 */
	public function checkFields(\App\OfferProfileRules\Fields $fields)
	{
		return $this->checkField($fields->passengerType);
	}


	/**
	 *
	 * {@inheritDoc}
	 * @see \App\OfferProfileRules\CriterionAbstract::checkAssignedValues()
	 */
	public function checkAssignedValues(\App\MessagesCollector $msgs)
	{
		// load configs
		$CFG = \Engine\Loader_Cfg::getInstance()->getGlobal();

		if (!$this->values) {
			$msgs->addWarning("No passenger type set");
		}
		else {
			foreach ($this->values as $elem) {
				if (!in_array($elem, $CFG['generalData']['personTypes'])) {
					$msgs->addWarning("The passenger type `{$elem}` is not valid.");
				}
			}
		}
	}


	/**
	 *
	 * {@inheritDoc}
	 * @see \App\OfferProfileRules\CriterionAbstract::createDescription_getEntityName()
	 */
	protected function createDescription_getEntityName($code)
	{
		$_LANG = \App\Loader_Lang::getInstance()->getGlobal();
		return $_LANG['generalData']['personTypes'][$code];
	}
}
