using CMSMicroservice.Protobuf.Protos.Tag;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.TagCQ.Commands.CreateNewTag;
using CMSMicroservice.Application.TagCQ.Commands.UpdateTag;
using CMSMicroservice.Application.TagCQ.Commands.DeleteTag;
using CMSMicroservice.Application.TagCQ.Queries.GetTag;
using CMSMicroservice.Application.TagCQ.Queries.GetAllTagByFilter;
using CMSMicroservice.Application.TagCQ.Queries.GetProductsByTag;

namespace CMSMicroservice.WebApi.Services;
public class TagService : TagContract.TagContractBase
{
    private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;

    public TagService(IDispatchRequestToCQRS dispatchRequestToCQRS)
    {
        _dispatchRequestToCQRS = dispatchRequestToCQRS;
    }
    public override async Task<CreateNewTagResponse> CreateNewTag(CreateNewTagRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<CreateNewTagRequest, CreateNewTagCommand, CreateNewTagResponse>(request, context);
    }
    public override async Task<Empty> UpdateTag(UpdateTagRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<UpdateTagRequest, UpdateTagCommand>(request, context);
    }
    public override async Task<Empty> DeleteTag(DeleteTagRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<DeleteTagRequest, DeleteTagCommand>(request, context);
    }
    public override async Task<GetTagResponse> GetTag(GetTagRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetTagRequest, GetTagQuery, GetTagResponse>(request, context);
    }
    public override async Task<GetAllTagByFilterResponse> GetAllTagByFilter(GetAllTagByFilterRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetAllTagByFilterRequest, GetAllTagByFilterQuery, GetAllTagByFilterResponse>(request, context);
    }

    public override async Task<GetProductsByTagResponse> GetProductsByTag(GetProductsByTagRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetProductsByTagRequest, GetProductsByTagQuery, GetProductsByTagResponse>(request, context);
    }
}
