// ReSharper disable InconsistentNaming

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

        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);
        }

        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);
        }

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