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

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

		if (in_array($transactionIndexes['source'], ['M3Hhl', 'M3Oths:HHL, M5->M3, M5->M1', 'M3Oths:HHL, M5->M3', ])) {
			return $this->_getData_M3Hhl();
		}
		elseif (in_array($transactionIndexes['source'], ['M3Oths:HHT', 'M3Oths:HHT, M5->M3', 'M3Oths:HHT, M5->M3, M5->M1',])) {
			return $this->_getData_M3Oths_HHL();
		}
		elseif (in_array($transactionIndexes['source'], ['M3Oths:HHX', 'M3Oths:HHX, M5->M3', 'M3Oths:HHX, M5->M3, M5->M1', ])) {
			return $this->_getData_M3Oths_HHX();
		}
		else {
			throw new \Exception(sprintf("Don't know how to interpret source '%s'", $transactionIndexes['source']));
		}
	}

	private function _getData_M3Hhl()
	{
		list($parsedStructure, , $transactionIndexes) = $this->getTransactionDetails();

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

		$M3 = $parsedStructure['M3'][$transactionIndexes['km3']];

		$item->occupancy = 	$M3['M3Hhl']['IU3PTY'];

		return $item;
	}

	private function _getData_M3Oths_HHL()
	{
		list($parsedStructure, , $transactionIndexes) = $this->getTransactionDetails();

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

		$M3 = $parsedStructure['M3'][$transactionIndexes['km3']];

		$item->occupancy = 	$M3['M3Oths']['IU3PTY'];

		return $item;
	}

	private function _getData_M3Oths_HHX()
	{
		list($parsedStructure, , $transactionIndexes) = $this->getTransactionDetails();

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

		$M3 = $parsedStructure['M3'][$transactionIndexes['km3']];

		$item->occupancy = 	$M3['M3Oths']['IU3PTY'];

		return $item;
	}
}
