using CMSMicroservice.Protobuf.Protos.Transactions;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.TransactionsCQ.Commands.CreateNewTransactions;
using CMSMicroservice.Application.TransactionsCQ.Commands.UpdateTransactions;
using CMSMicroservice.Application.TransactionsCQ.Commands.DeleteTransactions;
using CMSMicroservice.Application.TransactionsCQ.Queries.GetTransactions;
using CMSMicroservice.Application.TransactionsCQ.Queries.GetAllTransactionsByFilter;
using CMSMicroservice.Application.TransactionsCQ.Commands.VerifyTransaction;
using CMSMicroservice.Application.TransactionsCQ.Commands.RefundTransaction;

namespace CMSMicroservice.WebApi.Services;
public class TransactionsService : TransactionsContract.TransactionsContractBase
{
    private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;

    public TransactionsService(IDispatchRequestToCQRS dispatchRequestToCQRS)
    {
        _dispatchRequestToCQRS = dispatchRequestToCQRS;
    }
    public override async Task<CreateNewTransactionsResponse> CreateNewTransactions(CreateNewTransactionsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<CreateNewTransactionsRequest, CreateNewTransactionsCommand, CreateNewTransactionsResponse>(request, context);
    }
    public override async Task<Empty> UpdateTransactions(UpdateTransactionsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<UpdateTransactionsRequest, UpdateTransactionsCommand>(request, context);
    }
    public override async Task<Empty> DeleteTransactions(DeleteTransactionsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<DeleteTransactionsRequest, DeleteTransactionsCommand>(request, context);
    }
    public override async Task<GetTransactionsResponse> GetTransactions(GetTransactionsRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetTransactionsRequest, GetTransactionsQuery, GetTransactionsResponse>(request, context);
    }
    public override async Task<GetAllTransactionsByFilterResponse> GetAllTransactionsByFilter(GetAllTransactionsByFilterRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<GetAllTransactionsByFilterRequest, GetAllTransactionsByFilterQuery, GetAllTransactionsByFilterResponse>(request, context);
    }
    
    public override async Task<VerifyTransactionResponse> VerifyTransaction(VerifyTransactionRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<VerifyTransactionRequest, VerifyTransactionCommand, VerifyTransactionResponse>(request, context);
    }
    
    public override async Task<RefundTransactionResponse> RefundTransaction(RefundTransactionRequest request, ServerCallContext context)
    {
        return await _dispatchRequestToCQRS.Handle<RefundTransactionRequest, RefundTransactionCommand, RefundTransactionResponse>(request, context);
    }
}
