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

class Relations extends \App\Sabre\StructureParser\Structures\Base\Relations
{
	protected function _getData()
	{
		list($parsedStructure, , $transactionIndexes, $internalAssociations) = $this->getTransactionDetails();

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

		$relation = new \App\Sabre\StructureParser\Types\Relation();

		$M5 = $parsedStructure['M5'][$transactionIndexes['km5']];
		$M2 = $parsedStructure['M2'][$internalAssociations['M1->M2'][$transactionIndexes['km1']][0]];

		$relation->docNumber = $M5['previous_ticket'];
		if ($M2 && $M2['M2Var']['IU2IIE'] && $M2['M2Var']['IU2IIE']['previous_ticketDate']) {
			// $relation->docNumber = $M2['M2Var']['IU2IIE']['previous_ticket'];
			$relation->docDate =   $M2['M2Var']['IU2IIE']['previous_ticketDate'];
		}

		$relation->relationType = 'reissue';

		$item->appendRelation($relation);

		return $item;
	}
}
