using CMSMicroservice.Protobuf.Protos.User;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.UserCQ.Commands.CreateNewUser;
using CMSMicroservice.Application.UserCQ.Commands.UpdateUser;
using CMSMicroservice.Application.UserCQ.Commands.DeleteUser;
using CMSMicroservice.Application.UserCQ.Queries.GetUser;
using CMSMicroservice.Application.UserCQ.Queries.GetAllUserByFilter;
using CMSMicroservice.Application.UserCQ.Queries.GetJwtToken;
using CMSMicroservice.Application.UserCQ.Queries.AdminGetJwtToken;
using CMSMicroservice.Application.UserCQ.Commands.SetPasswordForUser;
namespace CMSMicroservice.WebApi.Services;
public class UserService : UserContract.UserContractBase
{
    private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;

    public UserService(IDispatchRequestToCQRS dispatchRequestToCQRS)
    {
        _dispatchRequestToCQRS = dispatchRequestToCQRS;
    }
    public override async Task<CreateNewUserResponse> CreateNewUser(CreateNewUserRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<CreateNewUserRequest, CreateNewUserCommand, CreateNewUserResponse>(request, context);
    }
    public override async Task<Empty> UpdateUser(UpdateUserRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<UpdateUserRequest, UpdateUserCommand>(request, context);
    }
    public override async Task<Empty> DeleteUser(DeleteUserRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<DeleteUserRequest, DeleteUserCommand>(request, context);
    }
    public override async Task<GetUserResponse> GetUser(GetUserRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetUserRequest, GetUserQuery, GetUserResponse>(request, context);
    }
    public override async Task<GetAllUserByFilterResponse> GetAllUserByFilter(GetAllUserByFilterRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetAllUserByFilterRequest, GetAllUserByFilterQuery, GetAllUserByFilterResponse>(request, context);
    }
    public override async Task<GetJwtTokenResponse> GetJwtToken(GetJwtTokenRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetJwtTokenRequest, GetJwtTokenQuery, GetJwtTokenResponse>(request, context);
    }
    public override async Task<AdminGetJwtTokenResponse> AdminGetJwtToken(AdminGetJwtTokenRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<AdminGetJwtTokenRequest, AdminGetJwtTokenQuery, AdminGetJwtTokenResponse>(request, context);
    }
    public override async Task<Empty> SetPasswordForUser(SetPasswordForUserRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<SetPasswordForUserRequest, SetPasswordForUserCommand>(request, context);
    }
}
