using System.Collections.Generic;
using XGame.Editor.Asset;
using XGame.Framework.Asset;

namespace XGame.Editor.Build.AssetBundles
{
    public class ManifestBundleBuildTask
    {
        private IBuildPipeline _buildPipeline;
        public ManifestBundleBuildTask(IBuildPipeline buildPipeline)
        {
            _buildPipeline = buildPipeline;
        }
        public bool Run()
        {
            var assetNames = new List<string>() { PathDefine.BundleManifestPath, PathDefine.SceneAssetBundleManifestPath, PathDefine.ReferenceManifestPath, PathDefine.ProductAssetManifestPath };
            var addressableNames = new List<string>() { Define.ASSET_BUNDLE_MANIFEST, Define.SCENE_BUNDLE_MANIFEST, Define.ASSET_REFERENCE_MANIFEST, Define.PRODUCT_ASSET_MANIFEST };
            if (System.IO.File.Exists(PathDefine.BuiltInAssetManifestPath))
            {
                assetNames.Add(PathDefine.BuiltInAssetManifestPath);
                addressableNames.Add(Define.BUILTIN_ASSET_MANIFEST);
            }
            var builds = new UnityEditor.AssetBundleBuild[]
            {
                new UnityEditor.AssetBundleBuild()
                {
                    assetBundleName = Define.MANIFEST_BUNDLE_NAME,
                    assetBundleVariant = Define.BUNDLE_VARIANT,
                    assetNames = assetNames.ToArray(),
                    addressableNames = addressableNames.ToArray(),
                }
            };
            return _buildPipeline.BuildAssetBundles(builds);
        }
    }
}
