<?php
namespace App\Amadeus\FileParser;

class Line_OPL extends \App\Amadeus\FileParser\LineAbstract
{
	/**
	 * 4.155. OPL PNR Remark
	 * see page 377(419)
	 *
	 * DETAILS
	 */
	protected $structure = [
		['name'=> 'MSGTAG',  'val' => 'OPL',   'type' => 'AN',      'req' => 'M',  'len' => 3,],  // 1 : Message Tag (OPL)
		['name'=> 'OPRMK',                     'type' => 'AN',      'req' => 'M',],               // 2 : OP PNR Remark Text
		['name'=> 'PSGASS',  'val' => ';P',    'type' => 'ASSOC',],
	];

	/**
	 * (non-PHPdoc)
	 * @see \App\Amadeus\FileParser\LineAbstract::parse()
	 */
	public function parse()
	{

		// seems that the OPRMK field can contain ';', so we need a custom parser in here
		// @see RO/Happy/2010-07-26_112639_86.122.56.8__@2600009.JUL

		$matches = [];
		preg_match("/^(?P<MSGTAG>OPL)(?P<OPRMK>.*?)(?P<PSGASS>\;P[0-9-,]+)?$/", $this->content, $matches);

		$this->tree['MSGTAG'] = $matches['MSGTAG'];
		$this->tree['OPRMK'] = 	$matches['OPRMK'];
		$this->tree['PSGASS'] = $matches['PSGASS'];

		$struct = $this->structure[2];
		if($matches['PSGASS'] && ($v = $this->parseFromStructure_v2_generalAssoc($struct, $this->tree['PSGASS'], 0, []))){
			$this->tree[$struct['name']] = $v['value'];
		}

		$this->postParse();
		return $this;
	}
}
