package com.fractalite.amad_ndc.convertersRQ;

import java.math.BigInteger;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import org.springframework.stereotype.Component;

import com.amadeus.xml.fmptbq_24_1_1a.*;
import com.amadeus.xml.fmptbq_24_1_1a.FareMasterPricerTravelBoardSearch.FareOptions;
import com.amadeus.xml.fmptbq_24_1_1a.FareMasterPricerTravelBoardSearch.Itinerary;


@Component
public class Fare_MasterPricerTravelBoardSearchRQ {
	
	
		public FareMasterPricerTravelBoardSearch buildFareMasterPricerTravelBoardSearch() {
			
			FareMasterPricerTravelBoardSearch search = new FareMasterPricerTravelBoardSearch();
			
			// Fare Options
			boolean sliceAndDice = true;
			search.setFareOptions(new FareOptions());
			priceTicketingInfo(search.getFareOptions(),  sliceAndDice);
			search.setNumberOfUnit(new NumberOfUnitsType());
			search.getNumberOfUnit().getUnitNumberDetail().add(createNumberOfUnitDetailsType312621C("RC",250));
			search.getNumberOfUnit().getUnitNumberDetail().add(createNumberOfUnitDetailsType312621C("PX",1));
			search.getPaxReference().addAll(paxReference(1,"ADT"));
			search.getItinerary().addAll(createItineraries());
			search.getItinerary().addAll(createItineraries2());
			
			//if (direct) {
			// "non-stop", "N"
			// "direct", "D"
			// "connecting","C"
		//direct flight
			ProductTypeDetailsType120801C df = new ProductTypeDetailsType120801C();
		//	ProductTypeDetailsType120801C.
		//Preferred Cabins
			CabinIdentificationType233500C cid = new CabinIdentificationType233500C();
			
		//preferred Carriers
			CompanyIdentificationType315715C ci = new CompanyIdentificationType315715C();
			
			
			return search;
		}
	
	
		private NumberOfUnitDetailsType312621C createNumberOfUnitDetailsType312621C(String unitType, int value) {
			NumberOfUnitDetailsType312621C ress=new NumberOfUnitDetailsType312621C();
			//ress.setTypeOfUnit("NDC");
			ress.setTypeOfUnit(unitType);

			ress.setNumberOfUnits(new BigInteger(""+value));
			return ress;
		}
		
		private Collection<TravellerReferenceInformationType230874S> paxReference(int paxNumber,String type){
			ArrayList<TravellerReferenceInformationType230874S> paxList=new ArrayList<TravellerReferenceInformationType230874S>();
			ArrayList<TravellerDetailsType> travellerDetailsTypeList =new ArrayList<TravellerDetailsType>();
			TravellerReferenceInformationType230874S pax=new TravellerReferenceInformationType230874S();
			pax.getPtc().add(type);
			TravellerDetailsType travellerDetailsType= new TravellerDetailsType();
			travellerDetailsType.setRef(new BigInteger(""+paxNumber));
			pax.getTraveller().add(travellerDetailsType);
			paxList.add(pax);
			return paxList;
		}
		
	private NumberOfUnitsType createUnitNumberDetail(String unitType, int value) {
		NumberOfUnitsType result = new NumberOfUnitsType();
		NumberOfUnitDetailsType312621C ress=new NumberOfUnitDetailsType312621C();
		ress.setTypeOfUnit("PX");
		ress.setNumberOfUnits(new BigInteger(""+value));
		result.getUnitNumberDetail().add(ress);
		return result;
	}
	
	private void priceFeeIdDescription(FareOptions fareOptions) {
		
		CodedAttributeType231453S feedId=new CodedAttributeType231453S();
		CodedAttributeInformationType316013C element= new CodedAttributeInformationType316013C();
		element.setFeeType("SBF");
		element.setFeeIdNumber("1");
		//CodedAttributeType214155S element =new CodedAttributeType214155S();
		//fareOptions.setFeeIdDescription(element);
	//	PricingTickInfo element = new PricingTickInfo();
		//fareOptions.setPricingTickInfo(element);
		feedId.getFeeId().add(element);
		///feedId.setFeeType("SBF");
		//feedId.setFeeIdNumber("1");

      //   element.getFeeId().add(feedId);
		fareOptions.getFeeIdDescription().getFeeId().add(element);
		
		
		//fareOptions.setFeeIdDescription(element);
		
		
	
		


	}
	
	private void priceTicketingInfo(FareOptions fareOptions, boolean sliceAndDice) {
		
		
		
		PricingTicketingDetailsType element = new PricingTicketingDetailsType();
		fareOptions.setPricingTickInfo(element);

		element.setPricingTicketing(new PricingTicketingInformationType());
		List<String> pricing = element.getPricingTicketing().getPriceType();

		// only request etickets obviously (in case)
		pricing.add("ET");

		// Published fares: RP
		pricing.add("RP");
		// TODO add RU unifares
		/*pricing.add("RU");
		// exclude low cost 
		pricing.add("XLC");

		// ticket-ability precheck
		pricing.add("TAC");
        
		// MTK multiple tickets

		if (sliceAndDice == false) {
			pricing.add("NSD");
		}*/

		// todo make corpid static;
		//String corpo = query.getOtherParamsFirst("corpid");
		
		//log.info("corporate id code : ", corpo);
		//corpo = "020993"; // RAM
		//corpo = "020996"; // RAM
	/*	if (corpo != null) {
			pricing.add("RW");
			CorporateIdentityType corporateId = new CorporateIdentityType();
			corporateId.setCorporateQualifier("RW");
			// "014157" coca cola for tests.
			corporateId.getIdentity().add(corpo);
			fareOptions.setCorporate(new CorporateIdentificationType());
			fareOptions.getCorporate().getCorporateId().add(corporateId);
		}
       log.info("peeee " +query.toString());
		// todo create constant
		if (query.hasFlag("nap")) {
			pricing.add("NAP");
		}
		if (query.hasFlag("npe")) {
			pricing.add("NPE");
		}
		if (query.hasFlag("nr")) {
			pricing.add("NR");
		}
		if (query.hasFlag("rf")) {
			pricing.add("RF");
		}
		if (query.hasFlag("pe")) {
		       log.info("pe14eee ");

			pricing.add("PE");
		}*/
		


	}
	
	

	private List<Itinerary> createItineraries() {

		List<Itinerary> result = new ArrayList<FareMasterPricerTravelBoardSearch.Itinerary>();
		FareMasterPricerTravelBoardSearch.Itinerary itinerary = new FareMasterPricerTravelBoardSearch.Itinerary();
		
		itinerary.setRequestedSegmentRef(new OriginAndDestinationRequestType());
		itinerary.getRequestedSegmentRef().setSegRef(
				new BigInteger(""+1));
		itinerary.setDepartureLocalization(new DepartureLocationType());
		itinerary.getDepartureLocalization().setDeparturePoint(
				new ArrivalLocationDetailsType120834C());
		itinerary.getDepartureLocalization().getDeparturePoint()
		.setLocationId("CDG");
		itinerary.setArrivalLocalization(new ArrivalLocalizationType());
		itinerary.getArrivalLocalization().setArrivalPointDetails(
				new ArrivalLocationDetailsType());
		
		itinerary.getArrivalLocalization().getArrivalPointDetails()
				.setLocationId("AMS");
		DateAndTimeInformationType181295S timeDetails = new DateAndTimeInformationType181295S();
		DateAndTimeDetailsTypeI FirstDateTimeDetail=new DateAndTimeDetailsTypeI();
		FirstDateTimeDetail.setDate("230425");
		timeDetails.setFirstDateTimeDetail(FirstDateTimeDetail);
		itinerary.setTimeDetails(timeDetails);
		//itinerary.getTimeDetails().getFirstDateTimeDetail().setDate("030425");
		
		
		result.add(itinerary);

		return result;
	}


	private List<Itinerary> createItineraries2() {

		List<Itinerary> result = new ArrayList<FareMasterPricerTravelBoardSearch.Itinerary>();
		FareMasterPricerTravelBoardSearch.Itinerary itinerary = new FareMasterPricerTravelBoardSearch.Itinerary();
		
		itinerary.setRequestedSegmentRef(new OriginAndDestinationRequestType());
		itinerary.getRequestedSegmentRef().setSegRef(
				new BigInteger(""+2));
		itinerary.setDepartureLocalization(new DepartureLocationType());
		itinerary.getDepartureLocalization().setDeparturePoint(
				new ArrivalLocationDetailsType120834C());
		itinerary.getDepartureLocalization().getDeparturePoint()
		.setLocationId("AMS");
		itinerary.setArrivalLocalization(new ArrivalLocalizationType());
		itinerary.getArrivalLocalization().setArrivalPointDetails(
				new ArrivalLocationDetailsType());
		
		itinerary.getArrivalLocalization().getArrivalPointDetails()
				.setLocationId("CDG");
		DateAndTimeInformationType181295S timeDetails = new DateAndTimeInformationType181295S();
		DateAndTimeDetailsTypeI FirstDateTimeDetail=new DateAndTimeDetailsTypeI();
		FirstDateTimeDetail.setDate("100525");
		timeDetails.setFirstDateTimeDetail(FirstDateTimeDetail);
		itinerary.setTimeDetails(timeDetails);
		//itinerary.getTimeDetails().getFirstDateTimeDetail().setDate("030425");
		
		
		result.add(itinerary);

		return result;
	}

	
}
