<?php
namespace App\Galileo\LineParser\Types;

/**
 * Data line
 * @author Lucian Sirbu
 */
class Data_A16B extends \App\Galileo\LineParser\Types\GalileoBase
{
	/**
	 *  "B" - CCR Car booked through CarMaster
	 */

	/**
	 * Children elements
	 */
	protected $children = [
		[ 'key'=>'A16SEC',  'type'=>'Constant', 'len'=>3, 'val'=>'A16',  'label'=>'SECTION LABEL "A16"' ],
		[ 'key'=>'A16TYP',  'type'=>'Constant', 'len'=>1, 'val'=>'B',    'label'=>'SEGMENT TYPE CODE' ],
		[ 'key'=>'A16NUM',  'type'=>'Integer',  'len'=>2,                'label'=>'ITINERARY INDEX NUMBER' ],
		[ 'key'=>'A16DTE',  'type'=>'Date',     'len'=>7,'store'=>'A16B_A16DTE','label'=>'PICK-UP DATE' ],
		[ 'key'=>'A16CAR',  'type'=>'Letters',  'len'=>12,               'label'=>'CAR RENTAL COMPANY' ],
		[ 'key'=>'A16STA',  'type'=>'Letters',  'len'=>2,                'label'=>'CAR ACTION/STATUS CODE' ],
		[ 'key'=>'A16CDT',  'type'=>'DateDDMMM','len'=>5, 'ref'=>'A16B_A16DTE','label'=>'CAR RETURN DATE' ],
		[ 'key'=>'A16DAY',  'type'=>'Integer',  'len'=>3,                'label'=>'NUMBER OF DAYS' ],
		[ 'key'=>'A16CCC',  'type'=>'StringTrim','len'=>4,                'label'=>'CAR CITY CODE' ],
		[ 'key'=>'A16CVC',  'type'=>'Letters',  'len'=>2,                'label'=>'CAR VENDOR CODE' ],
		[ 'key'=>'A16CCT',  'type'=>'Letters',  'len'=>4,                'label'=>'CAR TYPE' ],
		[ 'key'=>'A16CNI',  'type'=>'Integer',  'len'=>1,                'label'=>'NUMBER OF CARS' ],
		[ 'key'=>'A16PUP',  'type'=>'StringRaw',   'len'=>26,               'label'=>'CAR PICK-UP LOCATION' ],
		[ 'key'=>'A16DOL',  'type'=>'StringRaw',   'len'=>26,               'label'=>'CAR DROP OFF LOCATION' ],
		[ 'key'=>'A16PHN',  'type'=>'StringRaw',   'len'=>40,               'label'=>'TELEPHONE NUMBER FOR CAR PICK-UP LOCATION' ],
	];

	protected function postExtract(\App\Utils\BaseParser\TextParser\ExtractedBlock $ret)
	{
		$statuses = [
			'HK' => 'confirmed',
			'UC' => 'unconfirmed',
			'BK' => 'manual',
		];
		$ret->extractedData['A16STA_'] = $statuses[$ret->extractedData['A16STA']];

		return $ret;
	}
}
