using System;
using Intrepid.Diagnostics;
using Intrepid.TagSystem;
using Intrepid.Utilities;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Intrepid.Core.Tags
{
    [Serializable]
    [CreateAssetMenu(fileName = "New Scene Tag", menuName = "GON/Tags/Scene Tag")]
    public class SceneTag : Tag
    {
        public string SceneName => Code;
        
        [GroupDebug, Button(ButtonSizes.Medium, ButtonStyle.FoldoutButton, Icon = SdfIconType.Exclamation)]
        public void TestIfExists()
        {
            if (IsValid())
            {
                DLogger.LogDebug("scene exists");
                return;
            }
            DLogger.LogDebug("scene does not exists, check if scene name matches (or if it is not present on editor)");
        }

        public bool IsValid()
        {
            return SceneManager.GetSceneByName(SceneName).IsValid();
        }

        public bool IsReadyToBeLoaded()
        {
            return !IsValid();
        }
        
        public AsyncOperation LoadAsync(LoadSceneMode mode = LoadSceneMode.Additive)
        {
            return SceneManager.LoadSceneAsync(SceneName, mode);
        }

        public void UnloadAsync()
        {
            SceneManager.UnloadSceneAsync(SceneName);
        }
    }
}