<?php

namespace App\ImportedOrder\FormUtils;

class Customer extends GeneralAbstract
{

	/**
	 * The imported entity object.
	 * @var \App\ImportedOrder\Passenger
	 */
	protected $importedEntity;

	/**
	 * (non-PHPdoc)
	 * @see \App\ImportedOrder\FormUtils\GeneralAbstract::getFields()
	 */
	public function getFields()
	{

		$return = [];

		$return['lastName']['standard'] = $this->importedEntity->lastNameStandard;
		$return['middleName']['standard'] = $this->importedEntity->middleNameStandard;
		$return['firstName']['standard'] = $this->importedEntity->firstNameStandard;
		$return['lastName']['local'] = $this->importedEntity->lastNameLocal;
		$return['middleName']['local'] = $this->importedEntity->middleNameLocal;
		$return['firstName']['local'] = $this->importedEntity->firstNameLocal;

		if ($this->importedEntity->title) {
			$title = $this->importedEntity->title->getMatchedId($this->idSystem);
			if ($title) {
				$return['title'] = $title;
			}
		}
		if ($this->importedEntity->type) {
			$type = $this->importedEntity->type->getMatchedId($this->idSystem);
			if ($type) {
				$return['type'] = $type;
			}
		}

		if ($this->importedEntity->corporate) {
			$return['idCorporate']['id'] = $this->importedEntity->corporate->getMatchedId($this->idSystem);
		}

		$return['PNC'] = $this->importedEntity->PNC;
		$return['address'] = $this->importedEntity->address;
		$return['deliveryAddress'] = $this->importedEntity->deliveryAddress;
		$return['zipCode'] = $this->importedEntity->zipCode;
		$return['birthday'] = $this->importedEntity->birthday;
		$return['email'] = $this->importedEntity->email;
		$return['telephone'] = $this->importedEntity->telephone;
		$return['fax'] = $this->importedEntity->fax;
		$return['comments'] = $this->importedEntity->comments;
		$return['remarks'] = $this->importedEntity->remarks;

		if ($this->importedEntity->city) {
			$idCity = $this->importedEntity->city->getMatchedId($this->idSystem);
			if ($idCity) {
				$return['idLocation']['id'] = \Entity\City::select($idCity)->countryCode.'|'.$idCity;
			}
		}

		// add default passport
		$passport = $this->importedEntity->defaultPassport;

		if ($passport) {
			$return['passports'][1]['number'] = $passport->number;
			$return['passports'][1]['lastName'] = $passport->lastName;
			$return['passports'][1]['firstName'] = $passport->firstName;
			$return['passports'][1]['issueDate'] = $passport->issueDate;
			$return['passports'][1]['issuedBy'] = $passport->issuedBy;
			$return['passports'][1]['expireDate'] = $passport->expireDate;
			if ($passport->issueCountry) {
				$return['passports'][1]['issueCountryCode'] = $passport->issueCountry->getMatchedId($this->idSystem);
			}
			if ($passport->citizenship) {
				$return['passports'][1]['citizenship'] = $passport->citizenship->getMatchedId($this->idSystem);
			}
		}

		return $return;

	}

}