using CMSMicroservice.Protobuf.Protos.UserCarts;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.UserCartsCQ.Commands.CreateNewUserCarts;
using CMSMicroservice.Application.UserCartsCQ.Commands.UpdateUserCarts;
using CMSMicroservice.Application.UserCartsCQ.Commands.DeleteUserCarts;
using CMSMicroservice.Application.UserCartsCQ.Queries.GetUserCarts;
using CMSMicroservice.Application.UserCartsCQ.Queries.GetAllUserCartsByFilter;
using CMSMicroservice.Application.UserCartsCQ.Commands.ClearCart;

namespace CMSMicroservice.WebApi.Services;
public class UserCartsService : UserCartsContract.UserCartsContractBase
{
    private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;

    public UserCartsService(IDispatchRequestToCQRS dispatchRequestToCQRS)
    {
        _dispatchRequestToCQRS = dispatchRequestToCQRS;
    }
    public override async Task<CreateNewUserCartsResponse> CreateNewUserCarts(CreateNewUserCartsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<CreateNewUserCartsRequest, CreateNewUserCartsCommand, CreateNewUserCartsResponse>(request, context);
    }
    public override async Task<Empty> UpdateUserCarts(UpdateUserCartsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<UpdateUserCartsRequest, UpdateUserCartsCommand>(request, context);
    }
    public override async Task<Empty> DeleteUserCarts(DeleteUserCartsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<DeleteUserCartsRequest, DeleteUserCartsCommand>(request, context);
    }
    public override async Task<GetUserCartsResponse> GetUserCarts(GetUserCartsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetUserCartsRequest, GetUserCartsQuery, GetUserCartsResponse>(request, context);
    }
    public override async Task<GetAllUserCartsByFilterResponse> GetAllUserCartsByFilter(GetAllUserCartsByFilterRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetAllUserCartsByFilterRequest, GetAllUserCartsByFilterQuery, GetAllUserCartsByFilterResponse>(request, context);
    }
    
    public override async Task<ClearCartResponse> ClearCart(ClearCartRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<ClearCartRequest, ClearCartCommand, ClearCartResponse>(request, context);
    }
}
