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

class Passengers extends \App\Amadeus\StructureParser\Structures\Ticketing\Passengers
{

	public function getOwner()
	{
		$parsedStructure = $this->transaction->getParsedStructure();
//		$index = $this->transaction->getIndex();

		// initialize the return result
		$item = null;
		if(count($parsedStructure['I'])>1){
			$this->transaction->addLog(__METHOD__.": This reservation has more than one passenger, picking the first one as 'owner'");
		}

		$I = $parsedStructure['I'][0];

		if ($I && ($I['PSGRNME_firstName'] || $I['PSGRNME_lastName'])) {
			$item = new \App\Amadeus\StructureParser\Types\Passenger();

			$item->title = 		implode(" ", array_filter([$I['PSGRNME_honorifics_'], $I['PSGRNME_title_']]));
			$item->type = 		($I['PSGRID_']['type']?$I['PSGRID_']['type']:'adult');
			$item->firstName = 	$I['PSGRNME_firstName'];
			$item->lastName =	$I['PSGRNME_lastName'];

			$item = \App\Amadeus\StructureParser\Helpers::internal_passenger_extractAmadeusId($item, $I, $this->transaction, $parsedStructure);

			$this->passengers[] = $item;
		}

		return $this->passengers[0];
	}


	public function getAll()
	{
		return $this->passengers;
	}
}
