using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace SFramework.Editor
{
    public class SSymbolLinkHelper
    {
        public static string AssetBundlesLinkPath
        {
            get
            {
                // StreamingAssetsPath
                //return "Assets/StreamingAssets/" +
                //       KEngine.AppEngine.GetConfig(KEngineDefaultConfigs.StreamingBundlesFolderName);
                // hold asset bundles
                return "Assets/StreamingAssets/" + "Bundles";
            }
        }

        public static string GetLinkPath()
        {
            if (!System.IO.Directory.Exists(AssetBundlesLinkPath))
                System.IO.Directory.CreateDirectory(AssetBundlesLinkPath);
            return AssetBundlesLinkPath + "/" + SPlatformInfo.GetBuildPlatformName() + "/";
        }

        public static string GetResourceExportPath()
        {
            var resourcePath = SAssetsBundleHelper.GetExportPath(EditorUserBuildSettings.activeBuildTarget);
            return resourcePath;
        }

        [MenuItem("SFramework/Symbol Link Resources/Link Builded Resource -> StreamingAssets or Resources")]
        public static void SymbolLinkResource()
        {
            SUnityEditorTools.SUnityEditorTools.DeleteAllLinks(SSymbolLinkHelper.AssetBundlesLinkPath);

            var exportPath = GetResourceExportPath();
            var linkPath = GetLinkPath();

            SUnityEditorTools.SUnityEditorTools.SymbolLinkFolder(exportPath, linkPath);

            AssetDatabase.Refresh();
        }

        [MenuItem("SFramework/Symbol Link Resources/Remove StreamingAssets or Resources links")]
        public static void RemoveSymbolLinkResource()
        {
            SUnityEditorTools.SUnityEditorTools.DeleteAllLinks(SSymbolLinkHelper.AssetBundlesLinkPath);
            Debug.Log("Remove " + SSymbolLinkHelper.AssetBundlesLinkPath);

            AssetDatabase.DeleteAsset(SSymbolLinkHelper.AssetBundlesLinkPath);

            AssetDatabase.Refresh();
        }
    }
}