using System;
using System.IO;
using Abp.Extensions;
using Microsoft.AspNetCore.Hosting;

namespace YGNT.QuestionLibrary.Core.Helper
{
    public static class PathHelper
    {
        /// <summary>
        /// 获取试题解析基础路径
        /// </summary>
        /// <returns></returns>
        public static string GetBaseResolvePath()
        {
            return Path.Combine("Question", "Resolve");
        }

        /// <summary>
        /// 获取试卷生成基础路径
        /// </summary>
        /// <returns></returns>
        public static string GetBaseProducePath()
        {
            return Path.Combine("Question", "Produce");
        }

        /// <summary>
        /// 获取试题解析路径
        /// </summary>
        /// <returns></returns>
        public static string GetResolvePath()
        {
            return Path.Combine(GetBaseResolvePath(), Guid.NewGuid().ToString());
        }

        /// <summary>
        /// 获取试题解析图片路径
        /// </summary>
        /// <returns></returns>
        public static string GetResolveImgPath(string resolvePath)
        {
            return Path.Combine(resolvePath, "img");
        }

        /// <summary>
        /// 拼接root路径
        /// </summary>
        /// <param name="webHostEnvironment"></param>
        /// <param name="relativePath"></param>
        /// <returns>如果拼接的路径为空 则返回为空</returns>
        public static string SplicePath(this IWebHostEnvironment webHostEnvironment, string relativePath)
        {
            if (relativePath.IsNullOrEmpty())
                return string.Empty;
            return Path.Combine(webHostEnvironment.WebRootPath, relativePath);
        }
    }
}