<?php

namespace App\OfferProfileRules;

class Criterion_Supplier extends CriterionAbstract
{

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


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

		// check that at least one value set
		if (!$this->values) {
			$msgs->addWarning("No supplier set.");
		}
		else {
			// check the supplier id
			foreach($this->values as $idSupplier) {
				if (!\Entity\Supplier::select($idSupplier)->recordExists()) {
					$msgs->addWarning("The supplier id `{$idSupplier}` is not valid.");
				}
			}
		}

	}

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

}
