// ReSharper disable InconsistentNaming

using System;
using System.ComponentModel;

using ResponseModel = Sepehr.ApiGateway.Partners.Contracts.Flight.Availability.V17.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; }

        public bool RestrictedForTour { get; set; }

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

        [Browsable(false)]
        public Fare Child_Fare { get; set; }

        [Browsable(false)]
        public Fare Infant_Fare { get; set; }

        [Browsable(false)]
        public string CancelationPolicyList { get; set; }

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

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

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

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

            CancelationPolicyList = string.Join(
                separator: Environment.NewLine,
                values: flightClass
                    .CancelationPolicyList
                    .ConvertAll(x => x.Culture + Environment.NewLine + x.Text + Environment.NewLine + Environment.NewLine));

            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.Fare apiFare)
        {
            return new Fare
            {
                BaseFare = apiFare.BaseFare,
                TotalTax = apiFare.Tax,
                TotalFare = apiFare.TotalFare,
                Commission = apiFare.Commission,
                Markup = apiFare.Markup,
                Payable = apiFare.Payable,
            };
        }


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