using CMSMicroservice.Protobuf.Protos.Products;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.ProductsCQ.Commands.CreateNewProducts;
using CMSMicroservice.Application.ProductsCQ.Commands.UpdateProducts;
using CMSMicroservice.Application.ProductsCQ.Commands.DeleteProducts;
using CMSMicroservice.Application.ProductsCQ.Queries.GetProducts;
using CMSMicroservice.Application.ProductsCQ.Queries.GetAllProductsByFilter;
using CMSMicroservice.Application.ProductsCQ.Commands.BulkUpdateProductPrices;
using CMSMicroservice.Application.ProductsCQ.Commands.BulkUpdateProductStock;
using CMSMicroservice.Application.ProductsCQ.Queries.GetLowStockProducts;
using CMSMicroservice.Application.ProductsCQ.Commands.ToggleProductStatus;
namespace CMSMicroservice.WebApi.Services;
public class ProductsService : ProductsContract.ProductsContractBase
{
    private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;

    public ProductsService(IDispatchRequestToCQRS dispatchRequestToCQRS)
    {
        _dispatchRequestToCQRS = dispatchRequestToCQRS;
    }
    public override async Task<CreateNewProductsResponse> CreateNewProducts(CreateNewProductsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<CreateNewProductsRequest, CreateNewProductsCommand, CreateNewProductsResponse>(request, context);
    }
    public override async Task<Empty> UpdateProducts(UpdateProductsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<UpdateProductsRequest, UpdateProductsCommand>(request, context);
    }
    public override async Task<Empty> DeleteProducts(DeleteProductsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<DeleteProductsRequest, DeleteProductsCommand>(request, context);
    }
    public override async Task<GetProductsResponse> GetProducts(GetProductsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetProductsRequest, GetProductsQuery, GetProductsResponse>(request, context);
    }
    public override async Task<GetAllProductsByFilterResponse> GetAllProductsByFilter(GetAllProductsByFilterRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetAllProductsByFilterRequest, GetAllProductsByFilterQuery, GetAllProductsByFilterResponse>(request, context);
    }

    public override async Task<BulkUpdateProductPricesResponse> BulkUpdateProductPrices(BulkUpdateProductPricesRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<BulkUpdateProductPricesRequest, BulkUpdateProductPricesCommand, BulkUpdateProductPricesResponse>(request, context);
    }

    public override async Task<BulkUpdateProductStockResponse> BulkUpdateProductStock(BulkUpdateProductStockRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<BulkUpdateProductStockRequest, BulkUpdateProductStockCommand, BulkUpdateProductStockResponse>(request, context);
    }

    public override async Task<GetLowStockProductsResponse> GetLowStockProducts(GetLowStockProductsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetLowStockProductsRequest, GetLowStockProductsQuery, GetLowStockProductsResponse>(request, context);
    }

    public override async Task<ToggleProductStatusResponse> ToggleProductStatus(ToggleProductStatusRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<ToggleProductStatusRequest, ToggleProductStatusCommand, ToggleProductStatusResponse>(request, context);
    }
}
