using SepehrFlightApiSampleClient.Availability.WinForms.SearchByRouteAndDate.ViewModels;

namespace SepehrFlightApiSampleClient.Booking.WinForms.Book.BookCommand.Factory
{
    public class FactoryBasedOnSearchByRouteAndDateResult
    {
        public static Command Create(
            Flight selectedDepartureFlight,
            FlightClass selectedDepartureFlightClass,
            Flight selectedReturningFlight,
            FlightClass selectedReturningFlightClass)
        {
            var command = new Command
            {
                Departure = Convert(
                    selectedDepartureFlight, 
                    selectedDepartureFlightClass),
                Returning = Convert(
                    selectedReturningFlight, 
                    selectedReturningFlightClass),
            };

            return command;
        }

        private static FlightSegment Convert(
            Flight selectedFlight,
            FlightClass selectedFlightClass)
        {
            if (selectedFlight == null) return null;

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

            return commandFlightSegment;
        }
    }
}
