<?php
namespace App\Bsp\HotUA\Lines\Transaction;

/**
 * Line parser
 * @author Lucian Sirbu
 */
class BAR64 extends \App\Bsp\HotUA\HOTBase
{
	protected $children = [
		['key'=>'SMSG',                 'type'=>'Constant', 'val'=>'BAR',       'len'=>3,      'label'=>'Standard Message Identifier'],                   // X/M/Standard Message Identifier
		['key'=>'SQNR',                 'type'=>'Integer',                      'len'=>8,      'label'=>'Sequence Number'],                               // X/M/Sequence Number
		['key'=>'STNQ',                 'type'=>'Constant', 'val'=>'64',        'len'=>2,      'label'=>'Standard Numeric Qualifier'],                    // X/M/Standard Numeric Qualifier
		['key'=>'DAIS',                 'type'=>'Date',     'fmt'=>'YYMMDD',    'len'=>6,      'label'=>'Date of Issue'],                                 // X/M/Date of Issue
		['key'=>'TRNN',                 'type'=>'Integer',                      'len'=>6,      'label'=>'Transaction Number'],                            // X/M/Transaction Number
		['key'=>'TDNR_airline',         'type'=>'StringRaw',                    'len'=>3,      'label'=>'Ticket/Document Number(airline number)'],        // S/M/Ticket/Document Number
		['key'=>'TDNR_ticketNumber',    'type'=>'StringRaw',                    'len'=>10,     'label'=>'Ticket/Document Number'],
		['key'=>'TDNR_extra',           'type'=>'StringRaw',                    'len'=>1,      'label'=>'Ticket/Document Number(extra digits)'],
		['key'=>'CDGT',                 'type'=>'Digits',                       'len'=>1,      'label'=>'Check-Digit'],                                   // X/M/Check-Digit
		['key'=>'FARE_currency',        'type'=>'StringRaw',                    'len'=>3,      'label'=>'Fare'],                                          // X/M/Fare
		['key'=>'FARE_amount',          'type'=>'StringTrim',                   'len'=>9,      'label'=>'Fare'],
		['key'=>'TKMI',                 'type'=>'StringRaw',                    'len'=>1,      'label'=>'Ticketing Mode Indicator'],                      // X/M/Ticketing Mode Indicator
		['key'=>'EQFR_currency',        'type'=>'StringRaw',                    'len'=>3,      'label'=>'Equivalent Fare Paid'],                          // X/C/Equivalent Fare Paid
		['key'=>'EQFR_amount',          'type'=>'StringRaw',                    'len'=>9,      'label'=>'Equivalent Fare Paid'],
		['key'=>'TOTL',                 'type'=>'StringRaw',                    'len'=>12,     'label'=>'Total'],
		['key'=>'SASI',                 'type'=>'StringRaw',                    'len'=>4,      'label'=>'Servicing Airline/System Provider Identifier'],  // X/C/Servicing Airline/System Provider Identifier
		['key'=>'FCMI',                 'type'=>'StringRaw',                    'len'=>1,      'label'=>'Fare Calculation Mode Indicator'],               // X/M/Fare Calculation Mode Indicator
		['key'=>'BAID',                 'type'=>'StringRaw',                    'len'=>6,      'label'=>'Booking Agent Identification'],                  // X/C/Booking Agent Identification
		['key'=>'BEOT',                 'type'=>'StringTrim',                   'len'=>1,      'label'=>'Booking Entity Outlet Type'],                    // X/C/Booking Entity Outlet Type
		['key'=>'FCPI',                 'type'=>'StringRaw',                    'len'=>1,      'label'=>'Fare Calculation Pricing Indicator'],            // X/M/Fare Calculation Pricing Indicator
		['key'=>'RESD',                 'type'=>'StringTrim',                   'len'=>1,      'label'=>'Reserved Space'],                                //  /M/Reserved Space
	];

	protected function postExtract(\App\Utils\BaseParser\TextParser\ExtractedBlock $ret)
	{
		if (trim($ret->extractedData['TOTL'])=='NO ADC') {
			$ret->extractedData['TOTL'] = trim($ret->extractedData['TOTL']);
			$ret->extractedData['TOTL_currency'] = null;
			$ret->extractedData['TOTL_amount'] = null;
		}
		else {
			$ret->extractedData['TOTL_currency'] = substr($ret->extractedData['TOTL'], 0, 3);
			$ret->extractedData['TOTL_amount'] = (float)trim(substr($ret->extractedData['TOTL'], 3));
		}

		$ret->extractedData['EQFR_amount'] = trim($ret->extractedData['EQFR_amount']);
		if(is_numeric($ret->extractedData['EQFR_amount'])) {
			$ret->extractedData['EQFR_amount'] = (float)$ret->extractedData['EQFR_amount'];
		}

		return $ret;
	}
}
