using System.Collections.Generic;
using NUnit.Framework;
using Sirenix.Utilities;
using Test.Util;
using UnityEditor;
using UnityEngine;
using VOID.ScriptableObjects;

namespace Test.EditMode.GameData.Generic
{
    public class BasicStatusTest
    {
        private List<BasicStatus> _statuses = new();

        [OneTimeSetUp]
        public void Setup()
        {
            AssetDatabase.FindAssets($"t:{nameof(BasicStatus)}").ForEach(guid =>
            {
                var path = AssetDatabase.GUIDToAssetPath(guid);
                var status = AssetDatabase.LoadAssetAtPath<BasicStatus>(path);

                _statuses.Add(status);
            });
        }

        [OneTimeTearDown]
        public void Cleanup()
        {
            _statuses.Clear();
            _statuses = null;
        }

        [Test]
        public void DisplayName_IsPresent()
        {
            _statuses.ForEach(status =>
            {
                var assetPath = AssetDatabase.GetAssetPath(status.GetInstanceID());
                var assetHyperLink = DebugLogUtil.Hyperlink(assetPath);
                if (status.displayName.IsNullOrWhitespace())
                    Debug.LogError($"ScriptableObject: {assetHyperLink} display name is empty.", status);
            });
        }

        [Test]
        public void DisplayIcon_IsPresent()
        {
            _statuses.ForEach(status =>
            {
                var assetPath = AssetDatabase.GetAssetPath(status.GetInstanceID());
                var assetHyperLink = DebugLogUtil.Hyperlink(assetPath);
                if (!status.displayIcon)
                    Debug.LogError($"ScriptableObject: {assetHyperLink} display icon is not selected.", status);
            });
        }

        [Test]
        public void Description_IsPresent()
        {
            _statuses.ForEach(status =>
            {
                var assetPath = AssetDatabase.GetAssetPath(status.GetInstanceID());
                var assetHyperLink = DebugLogUtil.Hyperlink(assetPath);
                if (status.description.IsNullOrWhitespace())
                    Debug.LogError($"ScriptableObject: {assetHyperLink} description is empty.", status);
            });
        }

        [Test]
        public void DurationInTurns_NonNegative()
        {
            _statuses.ForEach(status =>
            {
                var assetPath = AssetDatabase.GetAssetPath(status.GetInstanceID());
                var assetHyperLink = DebugLogUtil.Hyperlink(assetPath);
                if (status.durationInTurns < 0)
                    Debug.LogError($"ScriptableObject: {assetHyperLink} duration cannot be negative.", status);
            });
        }
    }
}

