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

namespace SepehrTourApiSampleClient.Availability.GetHotelPackageList.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.Package package,
            string responseCurrencyCode)
        {
            this.Hotel = new Hotel.Hotel
            {
                SepehrGlobalId = package.Hotel.SepehrGlobalId,
                Name = package.Hotel.Name,
                RoomTypeList = package.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 = package.Hotel.AmenityList.ConvertAll(x => new Hotel.Amenity
                {
                    SepehrGlobalId = x.SepehrGlobalId,
                    Name = x.Name,
                    Quantity = x.Quantity,
                }),
            };

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

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

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