using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace YooAsset.Editor
{
	/// 
	/// 构建报告
	/// 
	[Serializable]
	public class BuildReport
	{
		/// 
		/// 汇总信息
		/// 
		public ReportSummary Summary = new ReportSummary();
		/// 
		/// 资源对象列表
		/// 
		public List AssetInfos = new List();
		/// 
		/// 资源包列表
		/// 
		public List BundleInfos = new List();
		/// 
		/// 冗余的资源列表
		/// 
		public List RedundancyInfos = new List();
		
		/// 
		/// 获取资源包信息类
		/// 
		public ReportBundleInfo GetBundleInfo(string bundleName)
		{
			foreach (var bundleInfo in BundleInfos)
			{
				if (bundleInfo.BundleName == bundleName)
					return bundleInfo;
			}
			throw new Exception($"Not found bundle : {bundleName}");
		}
		/// 
		/// 获取资源信息类
		/// 
		public ReportAssetInfo GetAssetInfo(string assetPath)
		{
			foreach (var assetInfo in AssetInfos)
			{
				if (assetInfo.AssetPath == assetPath)
					return assetInfo;
			}
			throw new Exception($"Not found asset : {assetPath}");
		}
		public static void Serialize(string savePath, BuildReport buildReport)
		{
			if (File.Exists(savePath))
				File.Delete(savePath);
			string json = JsonUtility.ToJson(buildReport, true);
			FileUtility.WriteAllText(savePath, json);
		}
		public static BuildReport Deserialize(string jsonData)
		{
			BuildReport report = JsonUtility.FromJson(jsonData);
			return report;
		}
	}
}