// ReSharper disable InconsistentNaming

using ResponseModel = Sepehr.ApiGateway.Partners.Contracts.Flight.Availability.V12.SearchByRouteAndDate.ResponseModel;

namespace SepehrFlightApiSampleClient.Availability.WinForms.SearchByRouteAndDate.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 Fare Adult_Fare { get; set; }

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

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

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

        [System.ComponentModel.Browsable(false)]
        public FreeBaggage AdultFreeBaggage { get; set; }

        [System.ComponentModel.Browsable(false)]
        public FreeBaggage ChildFreeBaggage { get; set; }

        [System.ComponentModel.Browsable(false)]
        public FreeBaggage InfantFreeBaggage { get; set; }

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

            Adult_Fare = ConvertFareApiModelToViewModel(flightClass.AdultFare);
            Child_Fare = ConvertFareApiModelToViewModel(flightClass.ChildFare);
            Infant_Fare = ConvertFareApiModelToViewModel(flightClass.InfantFare);

            AdultFreeBaggage = ConvertBaggageApiModelToViewModel(flightClass.AdultFreeBaggage);
            ChildFreeBaggage = ConvertBaggageApiModelToViewModel(flightClass.ChildFreeBaggage);
            InfantFreeBaggage = ConvertBaggageApiModelToViewModel(flightClass.InfantFreeBaggage);
        }

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

            Adult_Fare = ConvertFareApiModelToViewModel(flightClass.AdultFare);
            Child_Fare = ConvertFareApiModelToViewModel(flightClass.ChildFare);
            Infant_Fare = ConvertFareApiModelToViewModel(flightClass.InfantFare);

            AdultFreeBaggage = ConvertBaggageApiModelToViewModel(flightClass.AdultFreeBaggage);
            ChildFreeBaggage = ConvertBaggageApiModelToViewModel(flightClass.ChildFreeBaggage);
            InfantFreeBaggage = ConvertBaggageApiModelToViewModel(flightClass.InfantFreeBaggage);
        }

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

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


        private FreeBaggage ConvertBaggageApiModelToViewModel(ResponseModel.CharterFlight.FreeBaggage apiFreeBaggage)
        {
            return new FreeBaggage
            {
                CheckedBaggageQuantity = apiFreeBaggage.CheckedBaggageQuantity,
                CheckedBaggageTotalWeight = apiFreeBaggage.CheckedBaggageTotalWeight,
                HandBaggageQuantity = apiFreeBaggage.HandBaggageQuantity,
                HandBaggageTotalWeight = apiFreeBaggage.HandBaggageTotalWeight,
            };
        }

        private FreeBaggage ConvertBaggageApiModelToViewModel(ResponseModel.WebserviceFlight.FreeBaggage apiFreeBaggage)
        {
            return new FreeBaggage
            {
                CheckedBaggageQuantity = apiFreeBaggage.CheckedBaggageQuantity,
                CheckedBaggageTotalWeight = apiFreeBaggage.CheckedBaggageTotalWeight,
                HandBaggageQuantity = apiFreeBaggage.HandBaggageQuantity,
                HandBaggageTotalWeight = apiFreeBaggage.HandBaggageTotalWeight,
            };
        }
    }
}
