using CMSMicroservice.Protobuf.Protos.UserAddress;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.UserAddressCQ.Commands.CreateNewUserAddress;
using CMSMicroservice.Application.UserAddressCQ.Commands.UpdateUserAddress;
using CMSMicroservice.Application.UserAddressCQ.Commands.DeleteUserAddress;
using CMSMicroservice.Application.UserAddressCQ.Queries.GetUserAddress;
using CMSMicroservice.Application.UserAddressCQ.Queries.GetAllUserAddressByFilter;
using CMSMicroservice.Application.UserAddressCQ.Commands.SetAddressAsDefault;
namespace CMSMicroservice.WebApi.Services;
public class UserAddressService : UserAddressContract.UserAddressContractBase
{
    private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;

    public UserAddressService(IDispatchRequestToCQRS dispatchRequestToCQRS)
    {
        _dispatchRequestToCQRS = dispatchRequestToCQRS;
    }
    public override async Task<CreateNewUserAddressResponse> CreateNewUserAddress(CreateNewUserAddressRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<CreateNewUserAddressRequest, CreateNewUserAddressCommand, CreateNewUserAddressResponse>(request, context);
    }
    public override async Task<Empty> UpdateUserAddress(UpdateUserAddressRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<UpdateUserAddressRequest, UpdateUserAddressCommand>(request, context);
    }
    public override async Task<Empty> DeleteUserAddress(DeleteUserAddressRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<DeleteUserAddressRequest, DeleteUserAddressCommand>(request, context);
    }
    public override async Task<GetUserAddressResponse> GetUserAddress(GetUserAddressRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetUserAddressRequest, GetUserAddressQuery, GetUserAddressResponse>(request, context);
    }
    public override async Task<GetAllUserAddressByFilterResponse> GetAllUserAddressByFilter(GetAllUserAddressByFilterRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetAllUserAddressByFilterRequest, GetAllUserAddressByFilterQuery, GetAllUserAddressByFilterResponse>(request, context);
    }
    public override async Task<Empty> SetAddressAsDefault(SetAddressAsDefaultRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<SetAddressAsDefaultRequest, SetAddressAsDefaultCommand>(request, context);
    }
}
