using CMSMicroservice.Protobuf.Protos;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.PublicMessageCQ.Commands.CreatePublicMessage;
using CMSMicroservice.Application.PublicMessageCQ.Commands.UpdatePublicMessage;
using CMSMicroservice.Application.PublicMessageCQ.Commands.DeletePublicMessage;
using CMSMicroservice.Application.PublicMessageCQ.Commands.PublishMessage;
using CMSMicroservice.Application.PublicMessageCQ.Commands.ArchiveMessage;
using CMSMicroservice.Application.PublicMessageCQ.Queries.GetAllMessages;
using CMSMicroservice.Application.PublicMessageCQ.Queries.GetActiveMessages;
using CMSMicroservice.Application.PublicMessageCQ.Queries.GetPublicMessage;
using Google.Protobuf.WellKnownTypes;

namespace CMSMicroservice.WebApi.Services;

public class PublicMessageService : PublicMessageContract.PublicMessageContractBase
{
    private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;

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

    public override async Task<CreatePublicMessageResponse> CreatePublicMessage(CreatePublicMessageRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<CreatePublicMessageRequest, CreatePublicMessageCommand, CreatePublicMessageResponse>(request, context);
    }

    public override async Task<Empty> UpdatePublicMessage(UpdatePublicMessageRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<UpdatePublicMessageRequest, UpdatePublicMessageCommand>(request, context);
    }

    public override async Task<Empty> DeletePublicMessage(DeletePublicMessageRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<DeletePublicMessageRequest, DeletePublicMessageCommand>(request, context);
    }

    public override async Task<PublishMessageResponse> PublishMessage(PublishMessageRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<PublishMessageRequest, PublishMessageCommand, PublishMessageResponse>(request, context);
    }

    public override async Task<ArchiveMessageResponse> ArchiveMessage(ArchiveMessageRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<ArchiveMessageRequest, ArchiveMessageCommand, ArchiveMessageResponse>(request, context);
    }

    public override async Task<GetAllMessagesResponse> GetAllMessages(GetAllMessagesRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetAllMessagesRequest, GetAllMessagesQuery, GetAllMessagesResponse>(request, context);
    }

    public override async Task<GetActiveMessagesResponse> GetActiveMessages(GetActiveMessagesRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetActiveMessagesRequest, GetActiveMessagesQuery, GetActiveMessagesResponse>(request, context);
    }

    public override async Task<GetPublicMessageResponse> GetPublicMessage(GetPublicMessageRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetPublicMessageRequest, GetPublicMessageQuery, GetPublicMessageResponse>(request, context);
    }
}
