<?php
namespace App\Utils\BaseParser\Utils;

/**
 * Convert special meal codes to texts
 * @author Lucian Sirbu
 */
class SpecialMealRequestConvertor
{
	use \App\Utils\BaseParser\SingletonTrait;

	/**
	 * This list of from Amadeus, but other codes are available online
	 * @see JIRA:TD-2353
	 * @see http://www.vktravels.us/airlinesMealCodes.php
	 * @see http://www.emirates.com/english/plan_book/essential_information/dietary_requirements.aspx
	 * @see http://demo1.nkuht.edu.tw/~t0259/amadeus/mealcode.htm
	 * @var array
	 */
	protected $mealCodes = [
		['code'=>'AVML',  'label'=>'VEGETARIAN HINDU MEAL',                                                             'category'=>'MEAL',],
		['code'=>'BBML',  'label'=>'BABY MEAL',                                                                         'category'=>'MEAL',],
		['code'=>'BLML',  'label'=>'BLAND MEAL',                                                                        'category'=>'MEAL',],
		['code'=>'CHML',  'label'=>'CHILD MEAL',                                                                        'category'=>'MEAL',],
		['code'=>'DBML',  'label'=>'DIABETIC MEAL',                                                                     'category'=>'MEAL',],
		['code'=>'FPML',  'label'=>'FRUIT PLATTER MEAL',                                                                'category'=>'MEAL',],
		['code'=>'GFML',  'label'=>'GLUTEN INTOLERANT MEAL',                                                            'category'=>'MEAL',],
		['code'=>'HNML',  'label'=>'HINDU MEAL',                                                                        'category'=>'MEAL',],
		['code'=>'JPML',  'label'=>'JAPANESE MEAL (LH SPECIFIC - NEED AIRLINE ASSOCIATION)',                            'category'=>'MEAL',],
		['code'=>'KSML',  'label'=>'KOSHER MEAL',                                                                       'category'=>'MEAL',],
		['code'=>'LCML',  'label'=>'LOW CALORIE MEAL',                                                                  'category'=>'MEAL',],
		['code'=>'LFML',  'label'=>'LOW FAT MEAL',                                                                      'category'=>'MEAL',],
		['code'=>'LSML',  'label'=>'LOW SALT MEAL',                                                                     'category'=>'MEAL',],
		['code'=>'MOML',  'label'=>'MUSLIM MEAL',                                                                       'category'=>'MEAL',],
		['code'=>'NFML',  'label'=>'NO FISH MEAL (LH SPECIFIC - NEED AIRLINE ASSOCIATION)',                             'category'=>'MEAL',],
		['code'=>'NLML',  'label'=>'LOW LACTOSE MEAL',                                                                  'category'=>'MEAL',],
		['code'=>'RVML',  'label'=>'RAW VEGETARIAN MEAL',                                                               'category'=>'MEAL',],
		['code'=>'SFML',  'label'=>'SEA FOOD MEAL',                                                                     'category'=>'MEAL',],
		['code'=>'SPML',  'label'=>'SPECIAL MEAL, SPECIFY FOOD ITEMS',                                                  'category'=>'MEAL',],
		['code'=>'VGML',  'label'=>'VEGETARIAN VEGAN MEAL',                                                             'category'=>'MEAL',],
		['code'=>'VJML',  'label'=>'VEGETARIAN JAIN MEAL',                                                              'category'=>'MEAL',],
		['code'=>'VLML',  'label'=>'VEGETARIAN LACTO-OVO MEAL',                                                         'category'=>'MEAL',],
		['code'=>'VOML',  'label'=>'VEGETARIAN ORIENTAL MEAL',                                                          'category'=>'MEAL',],
		['code'=>'WCBD',  'label'=>'WHEELCHAIR-DRY CELL BATTERY',                                                       'category'=>'DISABLED',],
		['code'=>'WCBW',  'label'=>'WHEELCHAIR-WET CELL BATTERY',                                                       'category'=>'DISABLED',],
		['code'=>'WCHC',  'label'=>'WHEELCHAIR-ALL THE WAY TO SEAT',                                                    'category'=>'DISABLED',],
		['code'=>'WCHR',  'label'=>'WHEELCHAIR-FOR RAMP',                                                               'category'=>'DISABLED',],
		['code'=>'WCHS',  'label'=>'WHEELCHAIR-UP AND DOWN STEPS',                                                      'category'=>'DISABLED',],
		['code'=>'WCMP',  'label'=>'WHEELCHAIR-MANUAL POWER (US CARRIERS',                                              'category'=>'DISABLED',],
		['code'=>'WCOB',  'label'=>'WHEELCHAIR-ON BOARD',                                                               'category'=>'DISABLED',],
		['code'=>'STCR',  'label'=>'TRETCHER PASSENGER',                                                                'category'=>'DISABLED',],
		['code'=>'DPNA',  'label'=>'DISABLED PASSENGER WITH INTELLECTUAL OR DEVELOPMENT DISABILITY NEEDING ASSISTANCE', 'category'=>'DISABLED',],
		['code'=>'DEAF',  'label'=>'DEAF, SPECIFY IF ACCOMPANIED BY A GUIDE DOG',                                       'category'=>'DISABLED',],
		['code'=>'BLND',  'label'=>'BLIND, SPECIFY WHETHER OR NOT ACCOMPANIED BY GUIDE DOG',                            'category'=>'DISABLED',],
		['code'=>'SPEQ',  'label'=>'SPORTS EQUIPMENT',                                                                  'category'=>'OTHERS',],
		['code'=>'SEMN',  'label'=>'SEAMAN - SHIP\'S CREW',                                                             'category'=>'OTHERS',],
		['code'=>'BSCT',  'label'=>'BASSINET/CARRYCOT/BABY BASKET',                                                     'category'=>'OTHERS',],
	];

	/**
	 * Convert the given code to a string, used internally in TINA
	 * @param string $code
	 * @param string $airlineCode
	 * @return string|null
	 */
	public function convertMealCodeToName($code, $airlineCode=null)
	{
		$meal = $this->search($code, $airlineCode);
		if ($meal) {
			return $meal['label'];
		}

		return null;
	}

	/**
	 * Convert the given code to a string, used internally in TINA
	 * @param string $code
	 * @param string $airlineCode
	 * @return string|null
	 */
	public function convertMealCodeToCategory($code, $airlineCode=null)
	{
		$meal = $this->search($code, $airlineCode);
		if ($meal) {
			return $meal['category'];
		}

		return null;
	}

	/**
	 * Search the code
	 * @param string $code
	 * @param string $airlineCode
	 * @return string|null
	 */
	private function search($code, $airlineCode)
	{
		if ($code) {
			foreach ($this->mealCodes as $meal) {
				if ($meal['code']==$code) {
					return $meal;
				}
			}
		}

		return null;
	}
}
