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

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

		$item = new \App\Worldspan\StructureParser\Types\Price();

		$RO = $parsedStructure['MCO'][$transactionIndexes['MCOIdx']]['RO'];

		$currency = $this->determineCurrency($parsedStructure, [], [], [], [], $RO);

		$item->componentSet(new \App\Utils\BaseParser\Structure\StructureParser\Types\PriceComponent(
			'total',
			'RO:TotalAmountInformation',
			$RO['TotalAmountInformation'],
			null,
			($RO['TotalAmountInformationCurrency']?:$currency)
		));

		$item->componentSet(new \App\Utils\BaseParser\Structure\StructureParser\Types\PriceComponent(
			'supplier',
			'RO:AmountInformation',
			$RO['AmountInformation'],
			null,
			($RO['AmountInformationCurrency']?:$currency)
		));

		$item->componentSet(new \App\Utils\BaseParser\Structure\StructureParser\Types\PriceComponent(
			'commission',
			'RO:CommissionAmount',
			$RO['CommissionAmount'],
			null,
			($RO['AmountInformationCurrency']?:$currency)
		));

		$item->componentAdd(new \App\Utils\BaseParser\Structure\StructureParser\Types\PriceComponent(
			'supplier',
			'sub:commission',
			-1 * $item->commission,
			null,
			$item->commissionCurrency
		));

		if (!$item->formOfPayment->components) {
			$item = $this->intern_loadFormOfPaymentFromRO($item, $RO);
		}

		if (!$item->formOfPayment->components) {
			$item = $this->internal_extract_formOfPaymentFromR7($item, $parsedStructure['R7']);
		}

		return $item;
	}
}
