using System.Collections.Generic;
using NUnit.Framework;
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Settings.GroupSchemas;

namespace eagle0.Tests {
    [TestFixture]
    public class AddressablesBundlePolicyTests {
        [Test]
        public void MultiEntryPackedGroupsUseSeparateBundles() {
            var settings = AddressableAssetSettingsDefaultObject.Settings;
            Assert.NotNull(settings, "Addressable asset settings must exist.");

            var violations = new List<string>();
            foreach (var group in settings.groups) {
                if (group == null) { continue; }

                var bundledSchema = group.GetSchema<BundledAssetGroupSchema>();
                if (bundledSchema == null) { continue; }
                if (group.entries.Count <= 1) { continue; }

                if (bundledSchema.BundleMode !=
                    BundledAssetGroupSchema.BundlePackingMode.PackSeparately) {
                    violations.Add(
                            $"{group.Name}: {group.entries.Count} entries use {bundledSchema.BundleMode}");
                }
            }

            Assert.IsEmpty(
                    violations,
                    "Addressables groups with multiple entries must use PackSeparately. " +
                            "PackTogether can turn one prefab or sound change into a large bundle rebuild/upload:\n" +
                            string.Join("\n", violations));
        }
    }
}
