using Hotline.Application.Tests.Infrastructure;
using Hotline.Identity.Accounts;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Authentication;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using XF.Domain.Authentications;
using XF.Domain.Dependency;
using XF.Domain.Repository;

namespace Hotline.Application.Tests.Controller;
public class DefaultHttpContextAccessor : ISessionContext, IScopeDependency
{
    private HttpContext _content = new DefaultHttpContext();

    private HttpContext GetContext()
    {
        var context = new DefaultHttpContext();
        //var openId = new Claim(AppClaimTypes.OpenId, "测试生成的OpenId");
        var id = new ClaimsIdentity("身份");
        //id.AddClaim(openId);
        context.User = new ClaimsPrincipal(id);
        //OpenId = context.User.FindFirstValue(AppClaimTypes.OpenId);
        return context;

    }
    public HttpContext? HttpContext { get => GetContext(); set => _content = value; }


    public string? OpenId { get { return TestSessionConstants.OpenId; } set { } }

    /// <summary>
    /// Id of current tenant or null for host
    /// </summary>
    public string? UserId
    {
        get
        {
            return TestSessionConstants.UserId;
        }
        init { }
    }

    /// <summary>
    /// Id of current user or throw Exception for guest
    /// </summary>
    /// <exception cref="AuthenticationException"></exception>
    public string RequiredUserId { get { return TestSessionConstants.UserId; } }
    public string? UserName { get { return TestSessionConstants.UserName; } init { } }
    public string? Phone { get; init; }

    /// <summary>
    /// Roles
    /// </summary>
    public string[] Roles { get { return TestSessionConstants.Roles; } init { } }
    public string? OrgId { get { return TestSessionConstants.OrgId; } init { } }
    public string RequiredOrgId { get { return TestSessionConstants.OrgId; } }
    public string? OrgName { get; init; }
    public int OrgLevel { get; init; }
    public string? OrgAreaCode { get; init; }
    public bool OrgIsCenter { get; init; }

    /// <summary>
    /// 部门行政区划名称
    /// </summary>
    public string? OrgAreaName { get; init; }
    public string? AreaId { get; init; }
    public string? ClientId { get; init; }

    /// <summary>
    /// 工号
    /// </summary>
    public string? StaffNo { get; init; }
}
