using System;
using System.Collections.Generic;
using ViewModel = SepehrTourApiSampleClient.Availability.GetHotelPackageList.WinForms.ViewModels;
// ReSharper disable InconsistentNaming

namespace SepehrTourApiSampleClient.Booking.Book.WinForms.BookCommand.Factory
{
    public class FactoryBasedOnSearchByRouteAndDateResult
    {
        public static Command Create(
            string url,
            string username,
            string password,
            ViewModel.Flight.Flight selectedDepartureFlight,
            int? departureLockId,
            ViewModel.Flight.Flight selectedReturningFlight,
            int? returningLockId,
            decimal flight_totalPayable,
            DateTime checkinDate,
            DateTime checkoutDate,
            decimal hotel_TotalNetPrice_TaxIncluded,
            string hotelName,
            List<Hotel.Room> roomList,
            int hotelLockId)
        {
            var command = new Command
            {
                Url = url,
                Username = username,
                Password = password,
                DepartureFlight = Convert(
                    selectedDepartureFlight,
                    departureLockId),
                ReturningFlight = Convert(
                    selectedReturningFlight,
                    returningLockId),
                FlightTotalPayable = flight_totalPayable,
                Hotel = new Hotel.Hotel
                {
                    CheckinDate = checkinDate,
                    CheckoutDate = checkoutDate,
                    TotalNetPrice_TaxIncluded = hotel_TotalNetPrice_TaxIncluded,
                    HotelName = hotelName,
                    RoomList = roomList,
                    LockId = hotelLockId,
                },
            };

            return command;
        }

        private static Flight.FlightSegment Convert(
            ViewModel.Flight.Flight selectedFlight,
            int? lockId)
        {
            if (selectedFlight == null) return null;

            var commandFlightSegment = new Flight.FlightSegment
            {
                FlightNumber = selectedFlight.FlightNumber,
                DepartureDateTime = selectedFlight.DepartureDateTime,
                OriginIataCode = selectedFlight.Origin,
                DestinationIataCode = selectedFlight.Destination,
                FareName = selectedFlight.FareName,
                LockId = lockId,
                //AdultPayable = selectedFlightClass.WebserviceFare.OnewayFare.Adult_Fare.Payable,
                //ChildPayable = selectedFlightClass.WebserviceFare.OnewayFare.Child_Fare.Payable,
                //InfantPayable = selectedFlightClass.WebserviceFare.OnewayFare.Infant_Fare.Payable,
            };

            return commandFlightSegment;
        }
    }
}
