using CMSMicroservice.Protobuf.Protos.DiscountCategory;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.DiscountShopCQ.Commands.CreateDiscountCategory;
using CMSMicroservice.Application.DiscountShopCQ.Commands.UpdateDiscountCategory;
using CMSMicroservice.Application.DiscountShopCQ.Commands.DeleteDiscountCategory;
using CMSMicroservice.Application.DiscountShopCQ.Queries.GetDiscountCategories;

namespace CMSMicroservice.WebApi.Services;

public class DiscountCategoryService : DiscountCategoryContract.DiscountCategoryContractBase
{
    private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;

    public DiscountCategoryService(IDispatchRequestToCQRS dispatchRequestToCQRS)
    {
        _dispatchRequestToCQRS = dispatchRequestToCQRS;
    }

    public override async Task<CreateDiscountCategoryResponse> CreateDiscountCategory(CreateDiscountCategoryRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<CreateDiscountCategoryRequest, CreateDiscountCategoryCommand, CreateDiscountCategoryResponse>(request, context);
    }

    public override async Task<Empty> UpdateDiscountCategory(UpdateDiscountCategoryRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<UpdateDiscountCategoryRequest, UpdateDiscountCategoryCommand>(request, context);
    }

    public override async Task<Empty> DeleteDiscountCategory(DeleteDiscountCategoryRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<DeleteDiscountCategoryRequest, DeleteDiscountCategoryCommand>(request, context);
    }

    public override async Task<GetDiscountCategoriesResponse> GetDiscountCategories(GetDiscountCategoriesRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetDiscountCategoriesRequest, GetDiscountCategoriesQuery, GetDiscountCategoriesResponse>(request, context);
    }
}
