using System.Collections.Generic;
using ResponseModel = Sepehr.ApiGateway.Partners.Contracts.Hotel.Availability.V2.DateRange.ResponseModel;

namespace SepehrHotelApiSampleClient.Availability.GetByDateRange.WinForms.ViewModels
{
    public class Hotel
    {
        public int SepehrGlobalId { get; set; }

        public string Name { get; set; }

        public List<RoomType> RoomTypeList { get; set; }

        public Hotel(ResponseModel.Hotel hotel)
        {
            SepehrGlobalId = hotel.SepehrGlobalId;
            Name = hotel.Name;
            RoomTypeList = hotel.RoomTypeList.ConvertAll(roomType => ConvertRoomType(roomType));
        }

        private RoomType ConvertRoomType(ResponseModel.RoomType roomType)
        {
            var result = new RoomType
            {
                SepehrGlobalId = roomType.SepehrGlobalId,
                Name = roomType.Name,
                AdultCapacity = roomType.AdultCapacity,
                ChildCapacity = roomType.ChildCapacity,
                ChildAge = roomType.ChildAge,
                Hotel = this,
            };

            result.DateRangeList = roomType
                .DateRangeList
                .ConvertAll(dateRange => ConvertDateRange(dateRange, result));

            return result;
        }

        private static DateRange ConvertDateRange(
            ResponseModel.DateRange dateRange,
            RoomType roomType)
        {
            return new DateRange
            {
                CheckinDate = dateRange.CheckinDate,
                CheckoutDate = dateRange.CheckoutDate,
                AvailableRoomCount = dateRange.AvailableRoomCount,
                ExtrabedCapacity = dateRange.ExtrabedCapacity,
                RateDetailList = dateRange.RateDetailList.ConvertAll(rateDetail => new RateDetail
                {
                    Date = rateDetail.Date,
                    Room_BoardPrice_TaxIncluded = rateDetail.Room_BoardPrice_TaxIncluded,
                    Room_NetPrice_TaxExcluded = rateDetail.Room_NetPrice_TaxExcluded,
                    Room_NetPrice_TaxIncluded = rateDetail.Room_NetPrice_TaxIncluded,
                    Extrabed_BoardPrice_TaxIncluded = rateDetail.Extrabed_BoardPrice_TaxIncluded,
                    Extrabed_NetPrice_TaxExcluded = rateDetail.Extrabed_NetPrice_TaxExcluded,
                    Extrabed_NetPrice_TaxIncluded = rateDetail.Extrabed_NetPrice_TaxIncluded,
                }),
                RoomType = roomType,
            };
        }
    }
}
