<?php
namespace App\Amadeus\FileParser;

class Line_PPI extends \App\Amadeus\FileParser\LineAbstract
{
	/**
	 * 4.116. PPI Passenger data for Travel Assistance (Insurance)
	 * see page 298(340)
	 *
	 * This line item is used to transmit passenger-related data of the Amadeus Travel Assistance (Insurance) segment.
	 */
	protected $structure = [
		['name'=> 'MSGTAG',  'val' => 'PPI',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 1 : Message Tag (PPI)
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 2 : Delimiter (Constant value of ';')
		['name'=> 'PTCID',   'val' => 'INF',   'type' => 'AN',                                    'len' => 3,],                          // 3 : Infant identifier (Constant value of 'INF')
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 4 : Delimiter (Constant value of ';')
		['name'=> 'TVID',    'val' => 'TV-',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 5 : Trip value identifier (Constant value of 'TV-')
		['name'=> 'TVCURR',                    'type' => 'AN',                                    'len' => 3,],                          // 6 : Trip value currency
		['name'=> 'TVAMNT',                    'type' => 'AN',   'requires' => ['TVID',],  'len_min' => 1,   'len_max' => 18,],   // 7 : Trip value amount for passenger
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 8 : Delimiter (Constant value of ';')
		['name'=> 'SIID',    'val' => 'SI-',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 9 : Supplementary Information Identifier (Constant value of 'SI-')
		['name'=> 'SINFO',                     'type' => 'AN',                                    'len_min' => 1,   'len_max' => 70,],   // 10 : Supplementary Passenger Information
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 11 : Delimiter (Constant value of ';')
		['name'=> 'PVID',    'val' => 'PV-',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 12 : Premium Value identifier (Constant value of 'PV-')
		['name'=> 'PVCURR',                    'type' => 'AN',                                    'len' => 3,],                          // 13 : Premium Value Currency
		['name'=> 'PVAMNT',                    'type' => 'AN',   'requires' => ['PVID',],  'len_min' => 1,   'len_max' => 18,],   // 14 : Premium Value for passenger
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 15 : Delimiter (Constant value of ';')
		['name'=> 'BDAID',   'val' => 'BD-',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 16 : Birthday/age identifier (Constant value of 'BD-')
		['name'=> 'BDAGE',                     'type' => 'AN',                                    'len_min' => 5,   'len_max' => 20,],   // 17 : Birthday/age
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 18 : Delimiter (Constant value of ';')
		['name'=> 'PIDID',   'val' => 'PI-',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 19 : Passenger Identification Identifier (Constant value of 'PI-')
		['name'=> 'PIDENT',                    'type' => 'AN',                                    'len_min' => 1,   'len_max' => 42,],   // 20 : Passenger Identification
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 21 : Delimiter (Constant value of ';')
		['name'=> 'PPID',    'val' => 'PP-',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 22 : Passport Information Identifier (Constant value of 'PP-')
		['name'=> 'PPINFO',                    'type' => 'AN',                                    'len_min' => 1,   'len_max' => 30,],   // 23 : Passport Information
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 24 : Delimiter (Constant value of ';')
		['name'=> 'CCID',    'val' => 'CC-',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 25 : Credit Card Number Information (Constant value of 'CC-')
		['name'=> 'CCNBR',                     'type' => 'AN',                                    'len_min' => 1,   'len_max' => 23,],   // 26 : Credit Card Number (Composed by :Credit Card Company Credit Card NumberCredit Card Expiration date)
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 27 : Delimiter (Constant value of ';')
		['name'=> 'BENNM',   'val' => 'NB-',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 28 : Beneficiary Name identifier (Constant value of 'NB-')
		['name'=> 'BENNMDATA',                 'type' => 'AN',                                    'len_min' => 1,   'len_max' => 60,],   // 29 : Beneficiary Name details
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 30 : Delimiter (Constant value of ';')
		['name'=> 'GENDID',  'val' => 'GE-',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 31 : Gender Identifier (Constant value of 'GE-')
		['name'=> 'GENDER',                    'type' => 'AN',                                    'len_min' => 1,   'len_max' => 3,],    // 32 : Passenger Gender
		['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',      'req' => 'M',                 'len' => 1,],                          // 33 : Delimiter (Constant value of ';')
		['name'=> 'REDID',   'val' => 'FD-',   'type' => 'AN',      'req' => 'M',                 'len' => 3,],                          // 34 : Reduction Code Identifier (Constant value of 'FD-')
		['name'=> 'REDCODE',                   'type' => 'AN',                                    'len_min' => 1,   'len_max' => 3,],    // 35 : Reduction code
		['name'=> 'SEGASS',  'val' => ';S',    'type' => 'ASSOC',                                 'len' => 1,],                          // 36 : Segment Association
	];

	/**
	 * (non-PHPdoc)
	 * @see \App\Amadeus\FileParser\LineAbstract::postParse()
	 */
	protected function postParse()
	{
		// call the parent first
		parent::postParse();

		if ($this->tree['BDAGE']) {
			if (preg_match("/^[0-9]{2}[A-Z]{3}[0-9]{4}$/", $this->tree['BDAGE'])) {
				$this->tree['BDAGE_dateOfBirth'] = \App\Amadeus\FileParser\LineAbstract::extractDate($this->tree['BDAGE'], 'DDMMMYYYY', ['onlyPast'=>true]);
			}
		}
	}
}
