using SepehrTourApiSampleClient.BuiltinTypeExtensions;
using ResponseModel = Sepehr.ApiGateway.Partners.Contracts.Tour.Availability.V6.GetCheapestPrice.ResponseModel;

namespace SepehrTourApiSampleClient.Availability.GetCheapestPrice.WinForms.ViewModels
{
    public class Package
    {
        public Flight.Flight DepartureFlight { get; set; }

        public Flight.Flight ReturningFlight { get; set; }

        public Hotel.Hotel Hotel { get; set; }

        public decimal TotalFlightNetPrice { get; set; }

        public decimal TotalHotelNetPrice { get; set; }

        public decimal TotalGrossPrice { get; set; }

        public decimal TotalCommission { get; set; }

        public decimal TotalNetPrice { get; set; }

        public string CurrencyCode { get; set; }

        public Package(
            ResponseModel.CheapestPrice cheapestPrice,
            string responseCurrencyCode)
        {
            this.Hotel = new Hotel.Hotel
            {
                SepehrGlobalId = cheapestPrice.Hotel.SepehrGlobalId,
                Name = cheapestPrice.Hotel.Name,
                RoomTypeList = cheapestPrice.Hotel.RoomTypeList.ConvertAll(x => new Hotel.RoomType
                {
                    SepehrGlobalId = x.SepehrGlobalId,
                    Name = x.Name,
                    BoardTypeCode = x.BoardTypeCode,
                    AdultCount = x.AdultCount,
                    ChildAgeList = x.ChildAgeList,
                    ExtrabedAssignedCount = x.ExtrabedAssignedCount,
                }),
                AmenityList = cheapestPrice.Hotel.AmenityList.ConvertAll(x => new Hotel.Amenity
                {
                    SepehrGlobalId = x.SepehrGlobalId,
                    Name = x.Name,
                    Quantity = x.Quantity,
                }),
            };

            if (cheapestPrice.DepartureFlight != null)
            {
                this.DepartureFlight = new Flight.Flight
                {
                    FlightNumber = cheapestPrice.DepartureFlight.FlightNumber,
                    Origin = cheapestPrice.DepartureFlight.Origin.Code,
                    Destination = cheapestPrice.DepartureFlight.Destination.Code,
                    DepartureDateTime = cheapestPrice.DepartureFlight.DepartureDateTime,
                    ShamsiDepartureDateTime = cheapestPrice.DepartureFlight.DepartureDateTime.ParseFlightDate().MiladiToShamsi(),
                    Airline = cheapestPrice.DepartureFlight.Airline,
                    CabinType = cheapestPrice.DepartureFlight.CabinType,
                    BookingCode = cheapestPrice.DepartureFlight.BookingCode,
                    FareName = cheapestPrice.DepartureFlight.FareName,
                };
            }

            if (cheapestPrice.ReturningFlight != null)
            {
                this.ReturningFlight = new Flight.Flight
                {
                    FlightNumber = cheapestPrice.ReturningFlight.FlightNumber,
                    Origin = cheapestPrice.ReturningFlight.Origin.Code,
                    Destination = cheapestPrice.ReturningFlight.Destination.Code,
                    DepartureDateTime = cheapestPrice.ReturningFlight.DepartureDateTime,
                    ShamsiDepartureDateTime = cheapestPrice.ReturningFlight.DepartureDateTime.ParseFlightDate().MiladiToShamsi(),
                    Airline = cheapestPrice.ReturningFlight.Airline,
                    CabinType = cheapestPrice.ReturningFlight.CabinType,
                    BookingCode = cheapestPrice.ReturningFlight.BookingCode,
                    FareName = cheapestPrice.ReturningFlight.FareName,
                };
            }

            this.TotalFlightNetPrice = cheapestPrice.TotalFlightNetPrice;
            this.TotalHotelNetPrice = cheapestPrice.TotalHotelNetPrice;
            this.TotalGrossPrice = cheapestPrice.TotalGrossPrice;
            this.TotalCommission = cheapestPrice.TotalCommission;
            this.TotalNetPrice = cheapestPrice.TotalNetPrice;
            this.CurrencyCode = responseCurrencyCode;
        }
    }
}
