<?php
namespace App\Amadeus\FileParser;

class Line_FE extends \App\Amadeus\FileParser\LineAbstract
{
	/**
	 * 4.124. FE Endorsements/Restrictions
	 * see page 316(358)
	 *
	 * DETAILS
	 */
	protected $structure = [
		['name'=> 'MSGTAG',  'val' => 'FE',   'type' => 'AN',         'req' => 'M',  'len' => 2,],                          // 1 : Message Tag (FE)

		['name'=> 'ENDORSE',                  'type' => 'customCall', 'call'=> 'ENDORSE',],

		['name'=> 'SEGASS',  'val' => 'S',    'type' => 'ASSOC:loose',],
		['name'=> 'PSGASS',  'val' => 'P',    'type' => 'ASSOC:loose',],
	];

	function parseFromStructure_v2_custom_ENDORSE($tree, $struct, $content, $index, $options){
		// do the actual matcing
		$matches = [];
		preg_match("/^(?P<ENDORSE>.+?)(;S[0-9,\-]+)?(;P[0-9,\-]+)?$/", substr($content, $index), $matches);

		if ($matches) {
			$tree['ENDORSE'] = $matches['ENDORSE'];

			$ret = [];
			$ret['index'] = $index + strlen($matches['ENDORSE']);
			$ret['tree'] = $tree;
			$ret['skipStructIndex'] = true;

			return $ret;
		}

		return null;
	}
}
