<?php
namespace App\Amadeus\StructureParser\Structures\Train;

class ServiceDetails extends \App\Amadeus\StructureParser\Parser\ServiceDetails
{
	/**
	 * (non-PHPdoc)
	 * @see \App\Amadeus\StructureParser\Parser\ServiceDetails::getDetails()
	 */
	public function getDetails()
	{
		if($this->CACHE[__METHOD__]) return $this->CACHE[__METHOD__];

		$parsedStructure = $this->transaction->getParsedStructure();
		$indexType = $this->transaction->getIndexType();
		$index = $this->transaction->getIndex();
		$U = $parsedStructure['U'][$index->segment];

		if($indexType=='U' && $U['_type']=='17'){
			$details = $this->getDetails_U_17();
			if($details){
				$this->CACHE[__METHOD__] = $details;
				return $details;
			}
		}

		return null;
	}

	/**
	 * Extract data from a specific line
	 * @return \App\Amadeus\StructureParser\Types\ServiceDetails
	 */
	protected function getDetails_U_17()
	{
		$item = new \App\Amadeus\StructureParser\Types\ServiceDetails();
		$parsedStructure = $this->transaction->getParsedStructure();

		$item = $this->extractCommonServiceDetails($parsedStructure, $item);

		return $item;
	}


	/**
	 * (non-PHPdoc)
	 * @see \App\Amadeus\StructureParser\Parser\ServiceDetails::getRelations()
	 */
	public function getRelations()
	{
		if($this->CACHE[__METHOD__]) return $this->CACHE[__METHOD__];

		$parsedStructure = $this->transaction->getParsedStructure();
		$index = $this->transaction->getIndex();

		$relations = new \App\Amadeus\StructureParser\Types\Relations();

		$relations = $this->extractReferencesData($parsedStructure, $index, $relations);
		return $relations;
	}
}
