using eagle;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;

namespace eagle0.Tests {
    [TestFixture]
    public class EpidemicEffectMaterialTests {
        private const string EpidemicEffectPrefabPath =
                "Assets/Eagle/Effects/EpidemicEffect.prefab";
        private const string ParticleAlphaBlendMaterialPath =
                "Assets/Eagle/Effects/ParticleAlphaBlendMaterial.mat";
        private const string ClipRectParticleShaderName = "Eagle/ClipRectParticleUnlit";

        [Test]
        public void EpidemicEffectUsesSerializedParticleMaterials() {
            var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(EpidemicEffectPrefabPath);
            Assert.NotNull(prefab, $"{EpidemicEffectPrefabPath} must exist.");

            var effect = prefab.GetComponent<EpidemicEffect>();
            Assert.NotNull(effect, $"{EpidemicEffectPrefabPath} must include EpidemicEffect.");

            var expectedMaterial =
                    AssetDatabase.LoadAssetAtPath<Material>(ParticleAlphaBlendMaterialPath);
            Assert.NotNull(expectedMaterial, $"{ParticleAlphaBlendMaterialPath} must exist.");

            AssertUsesParticleMaterial(effect.skullMaterial, expectedMaterial, "skullMaterial");
            AssertUsesParticleMaterial(effect.hazeMaterial, expectedMaterial, "hazeMaterial");
        }

        private static void
        AssertUsesParticleMaterial(Material material, Material expectedMaterial, string fieldName) {
            Assert.AreSame(
                    expectedMaterial,
                    material,
                    $"EpidemicEffect.{fieldName} should serialize the shared particle material.");
            Assert.NotNull(material.shader, $"{fieldName} must have a shader.");
            Assert.AreEqual(
                    ClipRectParticleShaderName,
                    material.shader.name,
                    $"{fieldName} should use the project-owned URP clipped particle shader.");
        }
    }
}
