<?php
namespace App\Sabre\LineParser\Types\Line;

/**
 *
 * @author Lucian Sirbu
 */
class M1 extends \App\Sabre\LineParser\Types\SabreBaseLine
{
	/**
	 * M1 – Passenger Invoice Data Record
	 */

	/**
	 * Children elements
	 */
	protected $children = [
	    ['key'=>'IU1MID',    'type'=>'Constant',      'len'=>2,       'val'=>'M1',    'label'=>'IU1MID'],    // RECORD IDENTIFIER - "M1"
	    ['key'=>'IU1PNO',    'type'=>'StringTrim',    'len'=>2,                       'label'=>'IU1PNO'],    // INTERFACE NAME ITEM NUMBER
	    ['key'=>'IU1PNM',    'type'=>'StringTrim',    'len'=>64,                      'label'=>'IU1PNM'],    // PASSENGER NAME
	    ['key'=>'IU1PRK',    'type'=>'StringTrim',    'len'=>30,                      'label'=>'IU1PRK'],    // PASSENGER MAN NUMBER
	    ['key'=>'IU1IND',    'type'=>'StringTrim',    'len'=>1,                       'label'=>'IU1IND'],    // ADVANTAGE/AAIRPASS IND
	    ['key'=>'IU1AVN',    'type'=>'StringTrim',    'len'=>20,                      'label'=>'IU1AVN'],    // FREQUENT TRAVELER NUMBER
	    ['key'=>'IU1MLV',    'type'=>'StringTrim',    'len'=>5,                       'label'=>'IU1MLV'],    // FREQUENT TRAVELER MEMBERSHIP LEVEL
	    ['key'=>'IU1NM3',    'type'=>'Integer',       'len'=>2,                       'label'=>'IU1NM3'],    // NUMBER OF ITINERARIES - M3
	    ['key'=>'IU1TKT',    'type'=>'StringRaw',     'len'=>1,                       'label'=>'IU1TKT'],    // NAME SELECTED FOR TICKETING
	    ['key'=>'IU1SSM',    'type'=>'Constant',      'len'=>1,       'val'=>' ',     'label'=>'IU1SSM'],    // SPARE
	    ['key'=>'IU1NM5',    'type'=>'Integer',       'len'=>2,                       'label'=>'IU1NM5'],    // NUMBER OF ACCTG LINES - M5
	    ['key'=>'IU1NM7',    'type'=>'Integer',       'len'=>2,                       'label'=>'IU1NM7'],    // NUMBER OF ITINERARY REMARKS - M7, BLANK = PRINT REQUEST FOR ET
	    ['key'=>'IU1NM8',    'type'=>'Integer',       'len'=>2,                       'label'=>'IU1NM8'],    // NUMBER OF INVOICE REMARKS - M8, BLANK = PRINT REQUEST FOR ET
	    ['key'=>'IU1NM9',    'type'=>'Integer',       'len'=>2,                       'label'=>'IU1NM9'],    // NUMBER OF INTERFACE, REMARKS - M9, BLANK = PRINT REQUEST FOR ET
	    ['key'=>'IU1NMA',    'type'=>'StringTrim',    'len'=>2,                       'label'=>'IU1NMA'],    // RESERVED FOR FUTURE USE
	    ['key'=>'NL',        'type'=>'NewLine',],
	];


	/**
	 * (non-PHPdoc)
	 * @see \App\Utils\BaseParser\TextParser\BlockAbstract::postExtract()
	 */
	protected function postExtract(\App\Utils\BaseParser\TextParser\ExtractedBlock $ret)
	{
		$pn = new \App\Sabre\LineParser\PassengerNameParser();
		$pn->setText($ret->extractedData['IU1PNM']);
		$xtr = $pn->extract();

		$ret->extractedData['IU1PNM_'] = [
			'firstname' => 	$xtr->firstName,
			'lastname' =>  	$xtr->lastName,
			'title' =>  	$xtr->title,
			'type' =>  		$xtr->type,
		];

		return $ret;
	}

}
