#if !UNITY_2022_3_OR_NEWER
using UnityEditor;
using UnityEngine;

namespace WPFMA.Editor
{
    /// <summary>
    /// The only WPFMA-SDK script that runs on Unity older than 2022.3 (all the others switch themselves off there, so
    /// they never break the project). VRChat's current SDK and every tool WPFMA-SDK ships need Unity 2022.3, so this
    /// says how to move the project over instead of failing quietly.
    /// </summary>
    [InitializeOnLoad]
    internal static class WPFMAUnityVersionNotice
    {
        private const string ShownKey = "WPFMA.UnityVersionNotice.Shown";

        static WPFMAUnityVersionNotice()
        {
            EditorApplication.delayCall += Show;
        }

        private static void Show()
        {
            Debug.LogWarning("[WPFMA-SDK] This project is on Unity " + Application.unityVersion + ". WPFMA-SDK needs Unity 2022.3 " +
                             "(VRChat's current version), so it is switched off here. In the VRChat Creator Companion, open the project's " +
                             "menu and choose 'Change Unity Version' > 2022.3.22f1.");

            if (Application.isBatchMode || SessionState.GetBool(ShownKey, false))
                return;
            SessionState.SetBool(ShownKey, true);

            EditorUtility.DisplayDialog("WPFMA-SDK",
                "This project is on Unity " + Application.unityVersion + ".\n\n" +
                "WPFMA-SDK needs Unity 2022.3, the version VRChat uses now. The current VRChat SDK and the tools WPFMA-SDK " +
                "installs (Modular Avatar, NDMF, Gesture Manager...) only run on 2022.3, so WPFMA-SDK stays switched off here " +
                "and doesn't change anything in this project.\n\n" +
                "To use it: in the VRChat Creator Companion, open this project's menu (the three dots), choose 'Change Unity " +
                "Version', and pick 2022.3.22f1 (recommended). The Creator Companion backs the project up first.",
                "OK");
        }

        [MenuItem("WPFMA-SDK/Why is WPFMA-SDK off?")]
        private static void Explain()
        {
            SessionState.SetBool(ShownKey, false);
            Show();
        }
    }
}
#endif
