using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;

namespace Sched.CustomClasses
{
    public class AutoscheduleData : INotifyPropertyChanged
    {
        string _dayOfWeekStart;
        string _dayOfWeekEnd;
        int _periodStart;
        int _periodEnd;
        int _lessonTypePreference;

        public string DayOfWeekStart
        {
            get { return _dayOfWeekStart; }
            set { _dayOfWeekStart = value; OnPropertyChanged("DayOfWeekStart"); }
        }
        public string DayOfWeekEnd
        {
            get { return _dayOfWeekEnd; }
            set { _dayOfWeekEnd = value; OnPropertyChanged("DayOfWeekEnd"); }
        }
        public int PeriodStart
        {
            get { return _periodStart; }
            set { 
                if ((value>=1)&&(value <= 15))
                {
                    _periodStart = value;
                }
                OnPropertyChanged("PeriodStart"); }
        }
        public int PeriodEnd
        {
            get { return _periodEnd; }
            set {
                if ((value >= 1) && (value <= 15))
                {
                    _periodEnd = value;
                }
                OnPropertyChanged("PeriodEnd"); }
        }

        public int LessonTypePreference
        {
            get { return _lessonTypePreference; }
            set { _lessonTypePreference = value; OnPropertyChanged("LessonTypePreference"); }
        }


        public AutoscheduleData()
        {
            _dayOfWeekStart = "Monday";
            _dayOfWeekEnd = "Friday";
            _periodStart = 2;
            _periodEnd = 11;

            _lessonTypePreference = 1;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string info)
        {
            var handler = PropertyChanged;
            handler?.Invoke(this, new PropertyChangedEventArgs(info));
        }

        public static int GetWeekDayIndex(string dayName)
        {
            int i = 0;

            switch (dayName)
            {
                case "Monday":
                    i = 0;
                    break;
                case "Tuesday":
                    i = 1;
                    break;
                case "Wednesday":
                    i = 2;
                    break;
                case "Thursday":
                    i = 3;
                    break;
                case "Friday":
                    i = 4;
                    break;
                case "Saturday":
                    i = 5;
                    break;
                case "Sunday":
                    i = 6;
                    break;
                default:
                    i = -1;
                    break;
            }

            return i;
        }

        public List<int> GetDayPeriodRange()
        {
            List<int> sfd = new List<int>();
            sfd.Add(GetWeekDayIndex(_dayOfWeekStart));
            sfd.Add(GetWeekDayIndex(_dayOfWeekEnd));
            sfd.Add(_periodStart - 1);
            sfd.Add(_periodEnd - 1);

            return sfd;
        }

        public override string ToString()
        {
            return $"Day Start: {DayOfWeekStart}, Day End: {DayOfWeekEnd}";
        }
    }
}
