﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DNK.TourMLPriceSelector;

namespace DNK.PriceListImport.MetroClubLoader
{
    public class Hotel : RowMetroClub
    {
        private string _hotelName;
        private string _pansion;
        private int _indexTypePrice;
        private int _indexDurationPrice;
        public string HotelName { get { return _hotelName; } }
        public string Pansion { get { return _pansion; } }
        public int IndexTypePrice { get { return _indexTypePrice; } }
        public int IndexDurationPrice { get { return _indexDurationPrice; } }
        //--------------------------------------------------------------------------------------------
        public Hotel(string name)
        {
            this.name = name;
            this._indexTypePrice = -1;
            this._indexDurationPrice = -1;
            
            string[] words = name.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            if (words.Length > 0)
                _hotelName = words[0];
            if (words.Length > 1)
            {
                string[] words2 = words[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (words2.Length > 0)
                {
                    _indexTypePrice = GetIndexTypePrice(words2[0]);
                    _indexDurationPrice = GetIndexDurationPrice(words2[0]);
                }
                if (words2.Length > 1)
                {
                    _pansion = words2[1];
                }
            }
        }
        //--------------------------------------------------------------------------------------------
        private int GetIndexTypePrice(string source)
        {
            for (int i = 0; i < Constants.TypePrices.Length; i++)
            {
                if (source.Contains(Constants.TypePrices[i].Trim(), StringComparison.CurrentCultureIgnoreCase))
                {
                    return i;
                }
            }
            return -1;
        }
        //--------------------------------------------------------------------------------------------
        private int GetIndexDurationPrice(string source)
        {
            for (int i = 0; i < Constants.DurationPrices.Length; i++)
            {
                if (source.Contains(Constants.DurationPrices[i].Trim(), StringComparison.CurrentCultureIgnoreCase))
                {
                    return i;
                }
            }
            return -1;
        }
        //--------------------------------------------------------------------------------------------
        public List<DateRange> GetListDates(int index)
        {
            List<DateRange> result = null;
            if (columnValues.ContainsKey(index))
            {
                string[] strArray = columnValues[index].Split(new char[] { '\n', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < strArray.Length; i++)
                {
                    DateRange dateRange = DateRange.GetDatesFromRange(strArray[i]);
                    if (dateRange != null)
                    {
                        if (result == null)
                            result = new List<DateRange>();
                        result.Add(dateRange);
                    }
                }
            }
            return result;
        }
        //--------------------------------------------------------------------------------------------
        public string GetDate(int row)
        {
            if (columnValues != null && columnValues.ContainsKey(row))
                return columnValues[row];
            return null;
        }
        //--------------------------------------------------------------------------------------------
    }
}
