using XGame.Framework.Utils;
using System.IO;

namespace XGame.Framework.Define
{
    /// <summary>
    /// 框架用的 非AB文件 路径的静态定义
    /// 
    /// * 注意: 
    ///        1、请写相对路径  
    ///        2、相对于UpdatePath、WorkPath的路径
    /// </summary>
    public static class FileDefine
    {
        public const string ObsoleteAssetsPrefix = "ObsoleteAssets";

        public static readonly PathWrapper XGameDirectory = new("XGame");
    }

    /// <summary>
    /// XGame用的文件路径
    /// </summary>
    public struct PathWrapper
    {
        public string RelativePath { get; private set; }

        public PathWrapper(string relativePath)
        {
            RelativePath = relativePath;
        }

        /// <summary>
        /// AssetBundle文件(UpdateAssets ----no exist--->StreamAssets)
        /// </summary>
        public string AssetBundlePath => FileUtils.GetAssetBundlePath(RelativePath).Replace("\\", "/");
        /// <summary>
        /// 游戏文件路径(UpdateAssets ----no exist--->StreamAssets)
        /// </summary>
        public string FilePath => FileUtils.GetFilePath(RelativePath).Replace("\\", "/");
        /// <summary>
        /// 游戏文件URL(UpdateAssets ----no exist--->StreamAssets)
        /// </summary>
        public string UrlPath => FileUtils.GetFileUrl(RelativePath).Replace("\\", "/");
        /// <summary>
        /// 热更路径(UpdateAssets ----> no exist)(不会找包内路径，不存在就是不存在了)
        /// </summary>
        public string UpdatePath => Path.Combine(PathDefine.UpdatePath, RelativePath).Replace("\\", "/");
        /// <summary>
        /// 项目专用的沙盒目录(SandboxAssets ----> no exist)(不会找包内路径，不存在就是不存在了)
        /// </summary>
        public string SandboxPath => Path.Combine(PathDefine.SandboxPath, RelativePath).Replace("\\", "/");
        /// <summary>
        /// 包内StreamingAssets路径, 只读
        /// </summary>
        public string StreamingPath => Path.Combine(PathDefine.WorkPath, RelativePath).Replace("\\", "/");
        /// <summary>
        /// 沙盒根目录(Android下, Files目录, 项目禁止使用, 需要读写权限的目录请使用SandboxPath)
        /// </summary>
        internal string PersistentPath => Path.Combine(PathDefine.PersistentDataPath, RelativePath).Replace("\\", "/");

        /// <summary>
        /// 默认为FilePath！！
        /// </summary>
        /// <param name="wrapper"></param>
        public static implicit operator string(PathWrapper wrapper)
        {
            return wrapper.FilePath;
        }
    }
}
