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

/**
 * Data line
 * @author Lucian Sirbu
 */
class Data_A08 extends \App\Galileo\LineParser\Types\GalileoBase
{
	/**
	 *   FARE BASIS SECTION
	 */

	/**
	 * Children elements
	 */
	protected $children = [
		[ 'key'=>'A08SEC',  'type'=>'Constant',    'len'=>3, 'val'=>'A08',  'label'=>'SECTION LABEL "A08"' ],
		[ 'key'=>'A08FSI',  'type'=>'Integer',     'len'=>2,                'label'=>'FARE SECTION ID' ],
		[ 'key'=>'A08ITN',  'type'=>'Integer',     'len'=>2,                'label'=>'ITINERARY INDEX NUMBER' ],
		[ 'key'=>'A08FBC',  'type'=>'StringTrim',  'len'=>8,                'label'=>'FARE BASIS CODE' ],
		[ 'key'=>'A08VAL',  'type'=>'Integer',     'len'=>8,                'label'=>'SEGMENT VALUE' ],
		[ 'key'=>'A08NVBC', 'type'=>'Date',        'len'=>7,                'label'=>'NOT VALID BEFORE DATE' ],
		[ 'key'=>'A08NVAC', 'type'=>'Date',        'len'=>7,                'label'=>'NOT VALID AFTER DATE' ],
		[ 'key'=>'A08TDGC', 'type'=>'StringRaw',   'len'=>6,                'label'=>'SEGMENT TICKET DESIGNATOR' ],

		[ 'key'=>'taxes',   'merge'=>true, 'type'=>'OrderedComposer', 'req'=>false, 'children' => [
			[ 'key'=>'A08CFB',  'header'=>'F:',     'type'=>'StringTrim',  'len'=>15,               'label'=>'COMPLETE FARE BASIS CODE' ],
			[ 'key'=>'A08END',  'header'=>'E:',     'type'=>'StringRaw',   'len'=>60,               'label'=>'ENDORSEMENT' ],	// allow the tag to repeat
			[ 'key'=>'A08BAG',  'header'=>'B:',     'type'=>'StringRaw',   'len'=>3,                'label'=>'BAGGAGE ALLOWANCE' ],
		]],
	];

	protected function postExtract(\App\Utils\BaseParser\TextParser\ExtractedBlock $ret)
	{
		if ($ret->extractedData['A08END']) {
			$ret->extractedData['A08END'] = $this->helper->arr_rtrim(explode("E:", $ret->extractedData['A08END']));
		}

		$ret->extractedData['A08BAG_'] = $this->parse_tag_BAGGAGE($ret->extractedData['A08BAG']);

		return $ret;
	}
}
