<?php
namespace App\Sabre\StructureParser\Structures\MCO;

class Relations extends \App\Sabre\StructureParser\Structures\Base\Base
{
	/**
	 *
	 * {@inheritDoc}
	 * @see \App\Sabre\StructureParser\Structures\Base\Base::_getData()
	 */
	protected function _getData()
	{
		list($parsedStructure, , $transactionIndexes, ) = $this->getTransactionDetails();

		$item = new \App\Sabre\StructureParser\Types\Relations();

		$M5 = $parsedStructure['M5'][$transactionIndexes['km5']];

		$relatedM5s = [];

		foreach ($parsedStructure['M5'] as $oM5) {
			if (($M5!=$oM5) && ($M5['passengerName'] == $oM5['passengerName']) && $oM5['isTicketing_']) {
				$relatedM5s[]= $oM5;
			}
		}

		foreach ($relatedM5s as $oM5) {
			$relation = new \App\Sabre\StructureParser\Types\Relation();
			$relation->docNumber = $oM5['ticketNumber'];
			$relation->relationType = 'parent';
			$item->appendRelation($relation);
		}

		return $item;
	}
}
