<?php
namespace App\Galileo\StructureParser\Structures\Car;

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

		$A16 = $parsedStructure['A168'][0];

		$item = new \App\Galileo\StructureParser\Types\Itinerary();

		$segment = new \App\Galileo\StructureParser\Types\ItinerarySegment();

		// departure
		$dep = new \App\Galileo\StructureParser\Types\ItineraryLocation();
		$match = $this->match([
			'cityCode' => [$A16['A168']['A16CCC'],],
		]);
		$dep->suggest('cityCode', $A16['A168']['A16CCC']);

		$dep->airportCode = 	$match->airportCode;
		$dep->cityId = 			$match->cityId;
		$dep->countryCode = 	$match->countryCode;
		$dep->date = 			$A16['A168']['A16DTE'];
		$segment->departure = $dep;

		// destination
		$dest = new \App\Galileo\StructureParser\Types\ItineraryLocation();
		$match = $this->match([
			'cityCode' => [$A16['A168']['A16CCC'],],
		]);
		$dest->suggest('cityCode', $A16['A168']['A16CCC']);

		$dest->airportCode = 	$match->airportCode;
		$dest->cityId = 		$match->cityId;
		$dest->countryCode = 	$match->countryCode;
		$dest->date = 			$A16['A168']['A16CDT'];
		$segment->destination = $dest;

		$item->appendSegment($segment);
		return $item;
	}
}
