using System.Collections.Generic;
using System.Linq;
using BS.Shared;

namespace Config
{
    public class AppSettings
    {
        public static bool mIsServiceRecordNoticeMandatory = true;

        private bool mShowOnlyMySupportConcepts = true;

        private WindowStateType mWindowStateType = WindowStateType.Default;

        private ServiceRecordTimeInterval mLastSelectedServiceRecordTimeInterval = ServiceRecordTimeInterval.All;

        public enum WindowStateType
        {
            Default,
            Maximised
        }

        public bool IsServiceRecordNoticeMandatory
        {
            get { return mIsServiceRecordNoticeMandatory; }

            set { mIsServiceRecordNoticeMandatory = value; }
        }

        public int MaxDaysEditServiceRecordsAllowed { get; set; }

        public bool ShowAdvisedAttendedFlag { get; set; }

        private bool _showAllClients;

        public bool ShowAllClients
        {
            get { return _showAllClients; }
            set
            {
                if (_showAllClients != value)
                {
                    _showAllClients = value;
                    IsDirty = true;
                }
            }
        }

        public bool ShowDatevFields { get; set; }

        private bool _showExpiredSupportConcepts;

        public bool ShowExpiredSupportConcepts
        {
            get { return _showExpiredSupportConcepts; }
            set
            {
                if (_showExpiredSupportConcepts != value)
                {
                    _showExpiredSupportConcepts = value;
                    IsDirty = true;
                }
            }
        }

        private bool _showOnlyMyClients;

        public bool ShowOnlyMyClients
        {
            get { return _showOnlyMyClients; }
            set
            {
                if (_showOnlyMyClients != value)
                {
                    _showOnlyMyClients = value;
                    IsDirty = true;
                }
            }
        }

        private bool _showServiceRecordGridControl;

        public bool ShowServiceRecordGridControl
        {
            get { return _showServiceRecordGridControl; }
            set
            {
                if (_showServiceRecordGridControl != value)
                {
                    _showServiceRecordGridControl = value;
                    IsDirty = true;
                }
            }
        }

        public bool ShowLargeCustomerNotice { get; set; }

        public bool ShowOnlyMySupportConcepts
        {
            get { return mShowOnlyMySupportConcepts; }

            set
            {
                if (mShowOnlyMySupportConcepts != value)
                {
                    mShowOnlyMySupportConcepts = value;
                    IsDirty = true;
                }
            }
        }

        private string _startupPanelMaximized;

        public string StartupPanelMaximized
        {
            get { return _startupPanelMaximized; }
            set
            {
                string newValue = value;
                if (newValue == string.Empty)
                    newValue = null;
                if (_startupPanelMaximized != newValue)
                {
                    _startupPanelMaximized = value;
                    IsDirty = true;
                }
            }
        }

        private List<string> _startupPanelOrder;

        public List<string> StartupPanelOrder
        {
            get { return _startupPanelOrder; }
            set
            {
                if (IsOrderDifferent(_startupPanelOrder, value))
                {
                    _startupPanelOrder = value;
                    IsDirty = true;
                }
            }
        }

        private bool IsOrderDifferent(List<string> oldOrder, List<string> newOrder)
        {
            if (oldOrder == null && newOrder != null)
                return true;
            else if (oldOrder != null && newOrder == null)
                return true;
            else if (oldOrder != null && newOrder != null)
            {
                return oldOrder.Count != newOrder.Count || oldOrder.Where((t, i) => newOrder[i] != t).Any();
            }
            return false;
        }

        public WindowStateType WindowState
        {
            get { return mWindowStateType; }

            set
            {
                if (mWindowStateType != value)
                {
                    mWindowStateType = value;
                    IsDirty = true;
                }
            }
        }

        public ServiceRecordTimeInterval LastSelectedServiceRecordTimeInterval
        {
            get { return mLastSelectedServiceRecordTimeInterval; }

            set
            {
                if (mLastSelectedServiceRecordTimeInterval != value)
                {
                    mLastSelectedServiceRecordTimeInterval = value;
                    IsDirty = true;
                }
            }
        }

        public bool IsDirty { get; set; }

        public string TimeRecordingMenuName { get; set; }

        private int timeUntilUILock = 30;

        public int TimeUntilUILock
        {
            get { return timeUntilUILock; }

            set
            {
                if (timeUntilUILock != value)
                {
                    timeUntilUILock = value;
                    IsDirty = true;
                }
            }
        }
    }
}