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

namespace SepehrHotelApiSampleClient.Availability.GetByFromDateAndToDate.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
            {
                Date = dateRange.Date,
                AvailableRoomCount = dateRange.AvailableRoomCount,
                ExtrabedCapacity = dateRange.ExtrabedCapacity,
                HasCheckinLimit = dateRange.HasCheckinLimit,
                HasCheckoutLimit = dateRange.HasCheckoutLimit,
                MinimumStay = dateRange.MinimumStay,
                MaximumStay = dateRange.MaximumStay,
                Room_BoardPrice_TaxIncluded = dateRange.Room_BoardPrice_TaxIncluded,
                Room_NetPrice_TaxIncluded = dateRange.Room_NetPrice_TaxIncluded,
                RoomType = roomType,
            };
        }
    }
}
