using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace YooAsset.Editor
{
	[CreateAssetMenu(fileName = "AssetBundleCollectorSetting", menuName = "YooAsset/Create AssetBundle Collector Settings")]
	public class AssetBundleCollectorSetting : ScriptableObject
	{
		/// 
		/// 显示包裹列表视图
		/// 
		public bool ShowPackageView = false;
		/// 
		/// 启用可寻址资源定位
		/// 
		public bool EnableAddressable = false;
		/// 
		/// 资源定位地址大小写不敏感
		/// 
		public bool LocationToLower = false;
		/// 
		/// 包含资源GUID数据
		/// 
		public bool IncludeAssetGUID = false;
		/// 
		/// 资源包名唯一化
		/// 
		public bool UniqueBundleName = false;
		/// 
		/// 是否显示编辑器别名
		/// 
		public bool ShowEditorAlias = false;
		/// 
		/// 包裹列表
		/// 
		public List Packages = new List();
		/// 
		/// 清空所有数据
		/// 
		public void ClearAll()
		{
			ShowPackageView = false;
			EnableAddressable = false;
			LocationToLower = false;
			IncludeAssetGUID = false;
			UniqueBundleName = false;
			ShowEditorAlias = false;
			Packages.Clear();
		}
		/// 
		/// 检测配置错误
		/// 
		public void CheckConfigError()
		{
			foreach (var package in Packages)
			{
				package.CheckConfigError();
			}
		}
		/// 
		/// 修复配置错误
		/// 
		public bool FixConfigError()
		{
			bool isFixed = false;
			foreach (var package in Packages)
			{
				if (package.FixConfigError())
				{
					isFixed = true;
				}
			}
			return isFixed;
		}
		/// 
		/// 获取所有的资源标签
		/// 
		public List GetPackageAllTags(string packageName)
		{
			foreach (var package in Packages)
			{
				if (package.PackageName == packageName)
				{
					return package.GetAllTags();
				}
			}
			Debug.LogWarning($"Not found package : {packageName}");
			return new List();
		}
		/// 
		/// 获取包裹收集的资源文件
		/// 
		public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName)
		{
			if (string.IsNullOrEmpty(packageName))
				throw new Exception("Build package name is null or mepty !");
			foreach (var package in Packages)
			{
				if (package.PackageName == packageName)
				{
					CollectCommand command = new CollectCommand(buildMode, packageName,
						EnableAddressable, LocationToLower, IncludeAssetGUID, UniqueBundleName);
					CollectResult collectResult = new CollectResult(command);
					collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
					return collectResult;
				}
			}
			throw new Exception($"Not found collector pacakge : {packageName}");
		}
	}
}