<?php

namespace App\OfferProfileRules;

class Criterion_OfferDeparture_StationCode extends CriterionAbstract
{

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


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

		if (!$this->values and in_array($this->operation, ['equal', 'notEqual'])) {
			$msgs->addWarning("No departure station code set.");
		}
		else {
			foreach($this->values as $elem) {
				if (!\Entity\Station::select($elem)->recordExists()) {
					$msgs->addWarning("The station code `{$elem}` is not valid.");
				}
			}
		}

	}

	/**
	 * (non-PHPdoc)
	 * @see \App\OfferProfileRules\CriterionAbstract::createDescription_getEntityName()
	 */
	protected function createDescription_getEntityName($code)
	{
		return \Entity\Station::select($code)->name;
	}

}
