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

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

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

		$M5 = $parsedStructure['M5'][$transactionIndexes['km5']];
		if ($this->transaction->isTicketingIssue($parsedStructure, $transactionType, $transactionIndexes)) {
			if ($transactionIndexes['km5']!==null) {
				if ($M5['type_']==='6') {	// Manual Non-ARC/BSP Document
					$item->codeAirline = substr($M5['vendorCode'], -2);
				}
				else {
					$item->codeAirline = $M5['validatingCarrierCode'];
				}
			}
		}
		else {
			$processedRemarks = $this->transaction->remarks->getProcessedRemarks();
			$item->codeAirline = $processedRemarks['SUPPLIER'];
			$this->transaction->getMessagesCollector()->addInfo(sprintf("Supplier was loaded from remarks"));
		}

		return $item;
	}
}
