using NUnit.Framework;
using UnityEngine;
using UnityEngine.Rendering;

namespace eagle0.Tests {
    [TestFixture]
    public class URPPipelineSettingsTests {
        private const string PipelineTypeName = "UniversalRenderPipeline";

        [Test]
        public void GraphicsDefaultRenderPipelineIsUrp() {
            AssertUrpPipeline(
                    GraphicsSettings.defaultRenderPipeline,
                    "GraphicsSettings.defaultRenderPipeline");
        }

        [Test]
        public void ActiveQualityRenderPipelineIsUrp() {
            AssertUrpPipeline(
                    QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()),
                    $"QualitySettings active level '{QualitySettings.names[QualitySettings.GetQualityLevel()]}'");
        }

        [Test]
        public void AllQualityLevelsUseTheGraphicsUrpPipeline() {
            var defaultPipeline = GraphicsSettings.defaultRenderPipeline;
            AssertUrpPipeline(defaultPipeline, "GraphicsSettings.defaultRenderPipeline");

            for (var i = 0; i < QualitySettings.names.Length; i++) {
                var qualityPipeline = QualitySettings.GetRenderPipelineAssetAt(i);
                Assert.AreSame(
                        defaultPipeline,
                        qualityPipeline,
                        $"Quality level '{QualitySettings.names[i]}' should use the same URP asset as GraphicsSettings.");
            }
        }

        private static void AssertUrpPipeline(RenderPipelineAsset pipeline, string label) {
            Assert.NotNull(pipeline, $"{label} must be assigned.");
            StringAssert.Contains(
                    PipelineTypeName,
                    pipeline.GetType().Name,
                    $"{label} must be URP.");
        }
    }
}
