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

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

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

		if ($this->transaction->isTicketingIssue($parsedStructure, $transactionType, $transactionIndexes)) {
			if ($transactionIndexes['km5']!==null) {
				$item->docNumber = 		$parsedStructure['M5'][$transactionIndexes['km5']]['ticketNumber'];
				$item->docValidUntil = 	$parsedStructure['M4'][$transactionIndexes['km1']]['IU4NVA'];

				if ($parsedStructure['M5'][$transactionIndexes['km5']]['conjunctionTickets'] && $parsedStructure['M5'][$transactionIndexes['km5']]['conjunctionTickets']>1) {
					$item->conjunctionDocNumbers = \App\Utils\BaseParser\Utils\ConjunctionsTicketsConvertor::getInstance()->extractFromTicketAndCount($item->docNumber, $parsedStructure['M5'][$transactionIndexes['km5']]['conjunctionTickets']-1);
				}
			}

			$item->issueDate =	$parsedStructure['M0']['M0']['IU0MDT'];
			$item->docDate =	$item->issueDate;

			$item->docValidUntil = $parsedStructure['M4'][$transactionIndexes['km5']]['IU4NVA'];
		}
		else {
			$item->issueDate =	$parsedStructure['M0']['M0']['IU0MDT'];
			$item->docDate =	$item->issueDate;
		}

		$item = $this->populate($item, $parsedStructure, $transactionType, $transactionIndexes, $internalAssociations);

		return $item;
	}
}
