<?php

namespace App\ImportedOrder\PopulateEntity;

/**
 * The class is used for populating a customer entity object with data from an imported passenger (from imported order).
 * @author Gabriel
 */
class FrequentBuyerCard extends GeneralAbstract
{

	/**
	 * The imported entity (passenger fb card); this is redundant, it's added only for the IDE autocomplete to work.
	 * @var \App\ImportedOrder\Passenger_FbCard
	 */
	protected $importedEntity;

	/**
	 * The imported entity class name.
	 * @var String
	 */
	protected $importedEntityClass = '\App\ImportedOrder\Passenger_FbCard';

	/**
	 * The populating entity class name.
	 * @var String
	 */
	protected $populatingEntityClass = '\Entity\FrequentBuyerCard';

	/**
	 * (non-PHPdoc)
	 * @see \App\ImportedOrder\PopulateEntity\GeneralAbstract::populate()
	 */
	public function populate()
	{

		// add card number
		if ($this->importedEntity->number!==null) {
			$this->populatingEntity->cardNumber =			$this->importedEntity->number;
		}

		// add suppliers
		if ($this->importedEntity->suppliers) {
			$suppliersList = [];
			foreach($this->importedEntity->suppliers as $supp) {
				$idMatchedSupplier = $supp->getMatchedId($this->idExternalSystem);
				if ($idMatchedSupplier) {
					$suppliersList[] = $idMatchedSupplier;
				}
			}
			if ($suppliersList) {
				$this->populatingEntity->suppliersList = $suppliersList;
			}
		}

	}

}

