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

/**
 * Line parser
 * @author Lucian Sirbu
 */
class BKS24 extends \App\Bsp\Hot230\HOTBase
{
	protected $children = [
		[ 'key'=>'SMSG',  'type'=>'Constant', 'val'=>'BKS',          'len'=>3,      'label'=>'Standard Message Identifier', ],         // S/M/Standard Message Identifier
		[ 'key'=>'SQNR',  'type'=>'Integer',                         'len'=>8,      'label'=>'Sequence Number', ],                     // S/M/Sequence Number
		[ 'key'=>'STNQ',  'type'=>'Constant', 'val'=>'24',           'len'=>2,      'label'=>'Standard Numeric Qualifier', ],          // S/M/Standard Numeric Qualifier
		[ 'key'=>'DAIS',  'type'=>'Date',     'fmt'=>'YYMMDD',       'len'=>6,      'label'=>'Date of Issue', ],                       // S/M/Date of Issue
		[ 'key'=>'TRNN',  'type'=>'Integer',                         'len'=>6,      'label'=>'Transaction Number', ],                  // S/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', ],                         // S/M/Check Digit
		[ 'key'=>'CPUI',  'type'=>'StringRaw',                       'len'=>4,      'label'=>'Coupon Use Indicator', ],                // S/C/Coupon Use Indicator
		[ 'key'=>'CJCP',  'type'=>'StringTrim',                      'len'=>3,      'label'=>'Conjunction Ticket Indicator', ],        // S/C/Conjunction Ticket Indicator
		[ 'key'=>'AGTN',  'type'=>'Digits',                          'len'=>8,      'label'=>'Agent Numeric Code', ],                  // S/M/Agent Numeric Code
		[ 'key'=>'RFIC',  'type'=>'StringRaw',                       'len'=>1,      'label'=>'Reason for issuance code', ],
		[ 'key'=>'TOUR',  'type'=>'StringRaw',                       'len'=>15,     'label'=>'Tour Code', ],                           // S/C/Tour Code
		[ 'key'=>'TRNC',  'type'=>'StringRaw',                       'len'=>4,      'label'=>'Transaction Code', ],                    // S/M/Transaction Code
		[ 'key'=>'TODC',  'type'=>'StringRaw',                       'len'=>10,     'label'=>'True Origin/Destination City Codes', ],  // X/C/True Origin/Destination City Codes
		[ 'key'=>'PNRR',  'type'=>'StringRaw',                       'len'=>13,     'label'=>'PNR Reference and/or Airline Data', ],   // X/C/PNR Reference and/or Airline Data
		[ 'key'=>'TIIS',  'type'=>'StringRaw',                       'len'=>4,      'label'=>'Time of issue', ],
		[ 'key'=>'TACC',  'type'=>'StringRaw',                       'len'=>5,      'label'=>'Journey Tournaround Airport/City', ],
		[ 'key'=>'RESD',  'type'=>'StringTrim',                      'len'=>29,     'label'=>'Reserved Space', ],
	];


	protected function postExtract(\App\Utils\BaseParser\TextParser\ExtractedBlock $ret)
	{
		$TODC = rtrim($ret->extractedData['TODC']);
		if (strlen($TODC)==6) {
			$ret->extractedData['TODC_departure'] = substr($TODC, 0, 3);
			$ret->extractedData['TODC_destination'] = substr($TODC, 3, 3);
		}

		$PNRR = rtrim($ret->extractedData['PNRR']);
		$m = [];
		preg_match("/^(?P<RECLOC>[A-Z0-9]{6})\/(?P<supp>.+)/", $PNRR, $m);
		$ret->extractedData['PNRR_RECLOC'] = $m['RECLOC'];
		$ret->extractedData['PNRR_supplier'] = $m['supp'];

		return $ret;
	}
}
