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

/**
 * Data line
 * @author Lucian Sirbu
 */
class Data_A11 extends \App\Galileo\LineParser\Types\GalileoBase
{
	/**
	 *    FORM OF PAYMENT DATA
	 */

	/**
	 * Children elements
	 */
	protected $children = [
		[ 'key'=>'A11SEC',       'type'=>'Constant',    'len'=>3,  'val'=>'A11', 'label'=>'SECTION LABEL "A11"' ],
		[ 'key'=>'A11TYP',       'type'=>'StringRaw',   'len'=>2,                'label'=>'FORM OF PAYMENT TYPE FORM OF PAYMENT TYPE' ],
		[ 'key'=>'A11AMT',       'type'=>'Price',       'len'=>12,               'label'=>'PARTY AMOUNT ACTUALLY COLLECTED OR REFUNDED' ],
		[ 'key'=>'A11REF',       'type'=>'Letters',     'len'=>1,                'label'=>'REFUND INDICATOR' ],
		[ 'key'=>'A11CCC',       'type'=>'StringTrim',  'len'=>2,                'label'=>'CREDIT CARD CODE' ],
		[ 'key'=>'A11CCN',       'type'=>'StringTrim',  'len'=>20,               'label'=>'CREDIT CARD NUMBER' ],
		[ 'key'=>'A11EXP',       'type'=>'DateAuto',    'len'=>4,  'req'=>false, 'label'=>'CREDIT CARD EXPIRATION DATE' ],
		[ 'key'=>'A11APP',                                                       'label'=>'CREDIT CARD APPROVAL CODE', 'children' => [
			[ 'key'=>'A11BLK',   'type'=>'Letters',     'len'=>1,                'label'=>'BLANK' ],
			[ 'key'=>'A11MAN',   'type'=>'Letters',     'len'=>1,                'label'=>'APPROVAL CODE INDICATOR' ],
			[ 'key'=>'A11APC',   'type'=>'StringTrim',  'len'=>6,                'label'=>'ACTUAL CREDIT CARD - APPROVAL CODE' ],
			[ 'key'=>'A11PPO',   'type'=>'StringTrim',  'len'=>3,  'req'=>false, 'label'=>'PAYMENT PLAN OPTIONS' ],
		]],

		[ 'key'=>'taxes',   'merge'=>true, 'type'=>'OrderedComposer', 'req'=>false, 'children' => [
			[ 'key'=>'A11AVS',  'header'=>'A:',     'type'=>'Letters',     'len'=>1,      'label'=>'ADDRESS VERIFICATION INDICATOR' ],
			[ 'key'=>'A11CVS',  'header'=>'C:',     'type'=>'Letters',     'len'=>1,      'label'=>'CHECK VERIFICATION INDICATOR' ],
			[ 'key'=>'A11PGR',  'header'=>'P:',     'type'=>'Integer',     'len'=>2,      'label'=>'PASSENGER NUMBER' ],
			[ 'key'=>'A11FTXT', 'header'=>'F:',     'type'=>'StringRaw',   'len'=>41,     'label'=>'FREE TEXT DATA' ],
			[ 'key'=>'A11CCH',  'header'=>'H:',     'type'=>'StringRaw',   'len'=>30,     'label'=>'CUSTOMER FILE REFERENCE' ],
		]],
	];

	protected function postExtract(\App\Utils\BaseParser\TextParser\ExtractedBlock $ret)
	{
		// handle A11TYP
		$assoc  = [
			'S ' => 'cash',
			'CK' => 'cheque',
			'CC' => 'CC',
			'EX' =>	'exchange',
			'MS' => 'misc',
			'IN' => 'invoice',
			'NO' => 'NON REFUNDABLE',
			'MR' => 'MULTIPLE',
			'FR' => 'FREE',
		];
		$ret->extractedData['A11TYP_'] = $assoc[$ret->extractedData['A11TYP']];
		return $ret;
	}
}
