using CMSMicroservice.Protobuf.Protos.Role;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.RoleCQ.Commands.CreateNewRole;
using CMSMicroservice.Application.RoleCQ.Commands.UpdateRole;
using CMSMicroservice.Application.RoleCQ.Commands.DeleteRole;
using CMSMicroservice.Application.RoleCQ.Queries.GetRole;
using CMSMicroservice.Application.RoleCQ.Queries.GetAllRoleByFilter;
namespace CMSMicroservice.WebApi.Services;
public class RoleService : RoleContract.RoleContractBase
{
    private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;

    public RoleService(IDispatchRequestToCQRS dispatchRequestToCQRS)
    {
        _dispatchRequestToCQRS = dispatchRequestToCQRS;
    }
    public override async Task<CreateNewRoleResponse> CreateNewRole(CreateNewRoleRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<CreateNewRoleRequest, CreateNewRoleCommand, CreateNewRoleResponse>(request, context);
    }
    public override async Task<Empty> UpdateRole(UpdateRoleRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<UpdateRoleRequest, UpdateRoleCommand>(request, context);
    }
    public override async Task<Empty> DeleteRole(DeleteRoleRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<DeleteRoleRequest, DeleteRoleCommand>(request, context);
    }
    public override async Task<GetRoleResponse> GetRole(GetRoleRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetRoleRequest, GetRoleQuery, GetRoleResponse>(request, context);
    }
    public override async Task<GetAllRoleByFilterResponse> GetAllRoleByFilter(GetAllRoleByFilterRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetAllRoleByFilterRequest, GetAllRoleByFilterQuery, GetAllRoleByFilterResponse>(request, context);
    }
}
