using SepehrFlightApiSampleClient.Availability.WinForms.SearchByRouteAndDate.ViewModels;

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

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

            return 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,
            };
        }
    }
}
