using SepehrFlightApiSampleClient.Availability.WinForms.DateRange.ViewModels;

namespace SepehrFlightApiSampleClient.Booking.WinForms.Lock.LockCommand.Factory
{
    public class FactoryBasedOnDateRangeResult
    {
        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,
            };

            return commandFlightSegment;
        }
    }
}
