using JetBrains.Annotations;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering
{
    /// 
    /// Extensions for 
    /// 
    public static class BuildTargetExtensions
    {
        /// 
        /// Obtains a list of the  that are references into the settings either on  or in 
        /// 
        /// The type of 
        /// The  to obtain the assets.
        /// The output list of  that are referenced by the platform.
        /// false if there was an error fetching the  for this 
        [MustUseReturnValue]
        public static bool TryGetRenderPipelineAssets([DisallowNull] this BuildTarget buildTarget, List srpAssets)
            where T : RenderPipelineAsset
        {
            if (srpAssets == null)
                return false;
            var activeBuildTargetGroup = BuildPipeline.GetBuildTargetGroup(buildTarget);
            var activeBuildTargetGroupName = activeBuildTargetGroup.ToString();
            QualitySettings.GetRenderPipelineAssetsForPlatform(activeBuildTargetGroupName, out var buildPipelineAssets);
            srpAssets.AddRange(buildPipelineAssets);
            int count = QualitySettings.GetActiveQualityLevelsForPlatformCount(activeBuildTargetGroupName);
            var allQualityLevelsAreOverriden = buildPipelineAssets.Count == count;
            if (count == 0 || !allQualityLevelsAreOverriden)
            {
                // We need to check the fallback cases
                if (GraphicsSettings.defaultRenderPipeline is T srpAsset)
                    srpAssets.Add(srpAsset);
            }
            return true;
        }
    }
}