using System.Text.Json.Serialization;

namespace Microsoft.AspNetCore.Mvc
{
    abstract public class VersionIdModel
    {
        public int VersionId { get; set; } = 0;
    }

    public enum ViewMode
    {
        Full = 0,
        Partial = 1,
        IFrameFull = 2,
        IFramePartial = 3,
    }

    public class BaseViewModel : VersionIdModel
    {
        public bool NeedScripts { get; set; } = true;

        public ViewMode ViewMode { get; set; } = ViewMode.Full;

        public const string BootstrapVersionDefault = "5.3";
        public const string FaIconsVersionDefault = "6.5";

        #region Инфа по JQuery

        public bool JQueryRequired { get; set; } = true;

        #endregion

        #region Инфа по JSTree

        public bool JsTreeRequired { get; set; } = true;

        #endregion

        #region Инфа по бутстрапу

        public bool BootstrapRequired { get; set; } = true;
        public string BootstrapVersion { get; set; } = BootstrapVersionDefault;
        public bool CanLoadBootstrap { get => (BootstrapVersion ?? string.Empty).StartsWith(BootstrapVersionDefault); }
        public bool NeedLoadBootstrap { get => BootstrapRequired && CanLoadBootstrap; }
        public bool NeedDowngradeBootstrap { get => CanLoadBootstrap == false; }

        #endregion

        #region Инфа по иконкам

        [JsonPropertyName("faiRequired")]
        public bool FaIconsRequired { get; set; } = true;
        [JsonPropertyName("faiVersion")]
        public string FaIconsVersion { get; set; } = FaIconsVersionDefault;
        public bool CanLoadFaIcons { get => (FaIconsVersion ?? string.Empty).StartsWith(FaIconsVersionDefault); }
        public bool NeedLoadFaIcons { get => FaIconsRequired && CanLoadFaIcons; }
        public bool NeedDowngradeFaIcons { get => CanLoadBootstrap == false; }

        #endregion

        public BaseViewModel() { }
        public BaseViewModel(BaseViewModel baseViewModel)
        {
            if (baseViewModel == null) return;

            NeedScripts = baseViewModel.NeedScripts;
            ViewMode = baseViewModel.ViewMode;
            JQueryRequired = baseViewModel.JQueryRequired;
            JsTreeRequired = baseViewModel.JsTreeRequired;
            BootstrapRequired = baseViewModel.BootstrapRequired;
            BootstrapVersion = baseViewModel.BootstrapVersion;
            FaIconsRequired = baseViewModel.FaIconsRequired;
            FaIconsVersion = baseViewModel.FaIconsVersion;
        }

        public void RefillByViewMode()
        {
            if (ViewMode == ViewMode.IFrameFull || ViewMode == ViewMode.IFramePartial)
            {
                NeedScripts = true;

                BootstrapRequired = true;
                BootstrapVersion = BootstrapVersionDefault;

                FaIconsRequired = true;
                FaIconsVersion = FaIconsVersionDefault;

                JQueryRequired = true;
                JsTreeRequired = true;
            }
        }
    }
}