using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Text;

namespace AI.Platform.Core.Util
{
    public static class HttpRequestReader
    {
        private static IHttpContextAccessor? _httpContextAccessor;

        // 使用依赖注入配置静态属性
        public static void Configure(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
        public static Guid GetCurrentBuId()
        {
            if (_httpContextAccessor == null || _httpContextAccessor.HttpContext == null)
            {
                return Guid.Empty;
            }
            var httpContext = _httpContextAccessor.HttpContext;
            var headerValue = httpContext.Request.Headers["CurrentBuId"].ToString();
            if (string.IsNullOrEmpty(headerValue))
            {
                headerValue = httpContext.Request.Headers["currentbuid"].ToString();
            }
            if (Guid.TryParse(headerValue, out Guid buId))
            {
                return buId;
            }
            return Guid.Empty;
        }
        /// <summary>
        /// 小程序用户id
        /// </summary>
        /// <returns></returns>
        public static string GetWachatID()
        {
            if (_httpContextAccessor == null || _httpContextAccessor.HttpContext == null)
            {
                return null;
            }
            var httpContext = _httpContextAccessor.HttpContext;
            var headerValue = httpContext.Request.Headers["WachatID"].ToString();
            return headerValue;
        }
    }
}
