using System;
using InABox.Configuration;
using InABox.Core;
using System.Collections.Generic;

namespace InABox.Core
{
    public enum CoreFilterDefinitionVisibility
    {
        DesktopOnly,
        DesktopAndMobile
    }

    public static class CoreFilterDefinitionVisibilityExtensions
    {
        public static bool IsVisibleOn(this CoreFilterDefinitionVisibility visibility, Platform platform)
        {
            switch(platform)
            {
                case Platform.GPSEngine:
                case Platform.WebEngine:
                case Platform.DatabaseEngine:
                case Platform.SchedulerEngine:
                case Platform.Server:
                case Platform.Wpf:
                    return true;
                case Platform.TimeBench:
                    return visibility == CoreFilterDefinitionVisibility.DesktopAndMobile;
                default:
                    return false;
            }
        }
    }

    public interface ICoreFilterDefinition
    {
        string Name { get; }

        Filter<T>? AsFilter<T>();
    }

    public class CoreFilterDefinition : BaseObject, ISequenceable, ICoreFilterDefinition
    {
        [EditorSequence(1)]
        [TextBoxEditor]
        public string Name { get; set; } = "";

        [EditorSequence(2)]
        [FilterEditor]
        public string Filter { get; set; } = "";

        [EditorSequence(3)]
        [EnumLookupEditor(typeof(CoreFilterDefinitionVisibility), ToolTip = "On which platforms is this filter visible?", LookupWidth = 150)]
        [Caption("Visible On")]
        public CoreFilterDefinitionVisibility Visibility { get; set; } = CoreFilterDefinitionVisibility.DesktopOnly;

        [EditorSequence(4)]
        [CheckBoxEditor(ToolTip = "Is this filter private to you?")]
        [Security(typeof(CanEditGlobalFilters))]
        public bool Private { get; set; } = true;

        [NullEditor]
        public long Sequence { get; set; }

        public Filter<T>? AsFilter<T>()
        {
            return Serialization.Deserialize<Filter<T>>(Filter);
        }
        
        [NullEditor]
        public bool IsSelected { get; set; }
    }

    public class CoreFilterDefinitions : List<CoreFilterDefinition>, IGlobalConfigurationSettings, IUserConfigurationSettings
    {
        public CoreFilterDefinitions(): base()
        {

        }
        public CoreFilterDefinitions(int capacity) : base(capacity)
        {

        }
    }
    
}
