// ReSharper disable InconsistentNaming

using ResponseModel = Sepehr.ApiGateway.Partners.Contracts.Flight.Availability.V11.DateRange;

namespace SepehrFlightApiSampleClient.Availability.WinForms.DateRange.ViewModels
{
    public class FlightClass
    {
        public int AvailableSeat { get; set; }

        public string CabinType { get; set; }

        public string BookingCode { get; set; }

        public string FareName { get; set; }

        [System.ComponentModel.Browsable(false)]//I used thid attribute to hide this column on grid
        public FareGroup OnewayFare { get; set; }

        [System.ComponentModel.Browsable(false)]
        public FareGroup RoundtripFare_SameOrigin { get; set; }

        [System.ComponentModel.Browsable(false)]
        public FareGroup RoundtripFare_OppositeOrigin { get; set; }

        [System.ComponentModel.Browsable(false)]
        public string CancelationPolicy { get; set; }

        public FlightClass(ResponseModel.Charter.ResponseModel.FlightClass flightClass)
        {
            AvailableSeat = flightClass.AvailableSeat;
            CabinType = flightClass.CabinType;
            BookingCode = flightClass.BookingCode;
            FareName = flightClass.FareName;
            CancelationPolicy = flightClass.CancelationPolicy;

            this.OnewayFare = new FareGroup
            {
                Adult_Fare = ConvertFareApiModelToViewModel(flightClass.OnewayFare.Adult_Fare),
                Child_Fare = ConvertFareApiModelToViewModel(flightClass.OnewayFare.Child_Fare),
                Infant_Fare = ConvertFareApiModelToViewModel(flightClass.OnewayFare.Infant_Fare),
            };

            if (flightClass.RoundtripFare_SameOrigin != null)
            {
                this.RoundtripFare_SameOrigin = new FareGroup
                {
                    Adult_Fare = ConvertFareApiModelToViewModel(flightClass.RoundtripFare_SameOrigin.Adult_Fare),
                    Child_Fare = ConvertFareApiModelToViewModel(flightClass.RoundtripFare_SameOrigin.Child_Fare),
                    Infant_Fare = ConvertFareApiModelToViewModel(flightClass.RoundtripFare_SameOrigin.Infant_Fare),
                };
            }

            if (flightClass.RoundtripFare_OppositeOrigin != null)
            {
                this.RoundtripFare_OppositeOrigin = new FareGroup
                {
                    Adult_Fare = ConvertFareApiModelToViewModel(flightClass.RoundtripFare_OppositeOrigin.Adult_Fare),
                    Child_Fare = ConvertFareApiModelToViewModel(flightClass.RoundtripFare_OppositeOrigin.Child_Fare),
                    Infant_Fare = ConvertFareApiModelToViewModel(flightClass.RoundtripFare_OppositeOrigin.Infant_Fare),
                };
            }
        }

        public FlightClass(ResponseModel.Webservice.ResponseModel.FlightClass flightClass)
        {
            AvailableSeat = flightClass.AvailableSeat;
            CabinType = flightClass.CabinType;
            BookingCode = flightClass.BookingCode;
            FareName = flightClass.FareName;
            CancelationPolicy = flightClass.CancelationPolicy;

            this.OnewayFare = new FareGroup
            {
                Adult_Fare = ConvertFareApiModelToViewModel(flightClass.AdultFare),
                Child_Fare = ConvertFareApiModelToViewModel(flightClass.ChildFare),
                Infant_Fare = ConvertFareApiModelToViewModel(flightClass.InfantFare),
            };
        }

        private Fare ConvertFareApiModelToViewModel(ResponseModel.Charter.ResponseModel.Fare apiFare)
        {
            return new Fare
            {
                BaseFare = apiFare.BaseFare,
                Tax = apiFare.Tax,
                TotalFare = apiFare.TotalFare,
                Commision = apiFare.Commision,
                Payable = apiFare.Payable,
            };
        }

        private Fare ConvertFareApiModelToViewModel(ResponseModel.Webservice.ResponseModel.Fare apiFare)
        {
            return new Fare
            {
                BaseFare = apiFare.BaseFare,
                Tax = apiFare.Tax,
                TotalFare = apiFare.TotalFare,
                Commision = apiFare.Commision,
                Payable = apiFare.Payable,
            };
        }
    }
}
