using System;
using System.Threading.Tasks;
using Grpc.Core;
using gRPC.ZHiZHUN.AuthServer.protos;
using ZhiZhun.AuthenticationCenter.User;
using ZhiZhun.AuthenticationCenter.Utility;

namespace ZhiZhun.AuthenticationCenter.GrpcService
{
    public class GrpcTokenService: TokenGrpcService.TokenGrpcServiceBase
    {
        private readonly IJWTService _jwtService;

        public GrpcTokenService(IJWTService jwtService)
        {
            _jwtService = jwtService;
        }


          

        public override Task<GetTokenResponse> GetUserToken(GetTokenReuqest request, ServerCallContext context)
        {

            string token = _jwtService.GetToken(new UserBasicInfo()
            {
                Id = Guid.Parse(request.Id),
                RealName = request.RealName,
                ReviewerCode = request.ReviewerCode,
                UserName = request.UserName,
                UserTypeEnum = (UserType)request.UserTypeEnumInt,
                UserTypeShortName = request.UserTypeShortName
            });


            return Task.FromResult(new GetTokenResponse(){Code = 1,Token = token });
        }
    }
}