using EasyCaching.Core;
using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;

namespace IRaCIS.Core.API
{
    public interface IUploadClient
    {
        Task ReceivProgressAsync(string studyInstanceUid, int haveReceivedCount);
    }


    public class IRaCISUserIdProvider : IUserIdProvider
    {
        public virtual string GetUserId(HubConnectionContext connection)
        {
            return connection.User?.FindFirst(JwtIRaCISClaimType.Id)?.Value!;
        }
    }

    [AllowAnonymous]
    [DisableCors]
    public class UploadHub : Hub<IUploadClient>
    {

        public ILogger<UploadHub> _logger { get; set; }
        //public IUserInfo _userInfo { get; set; }
        public UploadHub(/*IUserInfo userInfo,*/ ILogger<UploadHub> logger)
        {
            //_userInfo = userInfo;

            _logger = logger;
        }

        public override Task OnConnectedAsync()
        {
            //base.Context.User.id
   

            _logger.LogError("连接: " + Context.ConnectionId);


            return base.OnConnectedAsync();
        }

        //public async Task SendProgress(string studyInstanceUid, int haveReceivedCount)
        //{


        //    await Clients.All.ReceivProgressAsync(studyInstanceUid, haveReceivedCount);
        //}

    }
}
