using Com.FirmLib.Bll;
using FWindSoft.DataFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Com.FirmLib.UI.BllCommon
{
    public static class FileUtils
    {
        /// <summary>
        /// 解析文件系统key值
        /// </summary>
        /// <param name="fileKey"></param>
        /// <returns></returns>
        public static FileItem ParseFileKey(string fileKey)
        {
            FileItem item = new FileItem();
            item.FileKey = fileKey ?? string.Empty;
            item.Name = BllFactory<FileBll>.Instance.GetSuffix(item.FileKey.ToString());
            return item;
        }
        /// <summary>
        /// 获取可用键值信息
        /// </summary>
        /// <param name="fileItem"></param>
        /// <param name="suffix"></param>
        /// <returns></returns>
        public static string GetUseKey(FileItem fileItem,string suffix)
        {
            if (fileItem == null)
            {
                return string.Empty;
            }
            if (!fileItem.ValidatePath)
            {
                return fileItem.FileKey;
            }
            string fileKey = string.Empty;
            if (fileItem.ValidateKey)
            {
                fileKey = fileItem.FileKey;
            }
            else
            {
                fileKey = BllFactory<FileBll>.Instance.CreateKey(fileItem.Name, suffix);
            }
            return fileKey;
        }
    }
}
