<?php

namespace App\OfferProfileRules;

class Criterion_OfferDeparture_CountryZone extends CriterionAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \App\OfferProfileRules\CriterionAbstract::checkFields()
	 */
	public function checkFields(\App\OfferProfileRules\Fields $fields)
	{
		return $this->checkField(\Entity\Country::select($fields->offerDepartureCountryCode)->zone);
	}


	/**
	 * (non-PHPdoc)
	 * @see \App\OfferProfileRules\CriterionAbstract::checkAssignedValues()
	 */
	public function checkAssignedValues(\App\MessagesCollector $msgs)
	{

		$CFG = \Engine\Loader_Cfg::getInstance()->getGlobal();

		if (!$this->values and in_array($this->operation, ['equal', 'notEqual'])) {
			$msgs->addWarning("No departure country zone set.");
		}
		else {
			foreach($this->values as $elem) {
				if (!in_array($elem, $CFG['countriesZones'])) {
					$msgs->addWarning("The country zone `{$elem}` is not valid.");
				}
			}
		}

	}

	/**
	 * (non-PHPdoc)
	 * @see \App\OfferProfileRules\CriterionAbstract::createDescription_getEntityName()
	 */
	protected function createDescription_getEntityName($code)
	{
		$_LANG = \App\Loader_Lang::getInstance()->getAll();
		return $_LANG['locations']['countriesZones'][$code];
	}

}
