{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}

module Utxorpc.Query (QueryHandlers (..), serviceHandlers) where

import Control.Monad.IO.Class (MonadIO)
import Network.GRPC.HTTP2.ProtoLens (RPC (RPC))
import Network.GRPC.Server (ServerStreamHandler, ServiceHandler, UnaryHandler)
import Proto.Utxorpc.V1alpha.Query.Query
import Utxorpc.Logged (UtxorpcServiceLogger, loggedSStream, loggedUnary)

data QueryHandlers m a = QueryHandlers
  { forall (m :: * -> *) a.
QueryHandlers m a
-> UnaryHandler m ReadParamsRequest ReadParamsResponse
readParams :: UnaryHandler m ReadParamsRequest ReadParamsResponse,
    forall (m :: * -> *) a.
QueryHandlers m a
-> UnaryHandler m ReadUtxosRequest ReadUtxosResponse
readUtxos :: UnaryHandler m ReadUtxosRequest ReadUtxosResponse,
    forall (m :: * -> *) a.
QueryHandlers m a
-> UnaryHandler m SearchUtxosRequest SearchUtxosResponse
searchUtxos :: UnaryHandler m SearchUtxosRequest SearchUtxosResponse,
    forall (m :: * -> *) a.
QueryHandlers m a
-> ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse a
streamUtxos :: ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse a
  }

serviceHandlers ::
  (MonadIO m) =>
  Maybe (UtxorpcServiceLogger m) ->
  (forall x. m x -> IO x) ->
  QueryHandlers m b ->
  [ServiceHandler]
serviceHandlers :: forall (m :: * -> *) b.
MonadIO m =>
Maybe (UtxorpcServiceLogger m)
-> (forall x. m x -> IO x) -> QueryHandlers m b -> [ServiceHandler]
serviceHandlers Maybe (UtxorpcServiceLogger m)
logger forall x. m x -> IO x
f QueryHandlers {UnaryHandler m ReadParamsRequest ReadParamsResponse
readParams :: forall (m :: * -> *) a.
QueryHandlers m a
-> UnaryHandler m ReadParamsRequest ReadParamsResponse
readParams :: UnaryHandler m ReadParamsRequest ReadParamsResponse
readParams, UnaryHandler m ReadUtxosRequest ReadUtxosResponse
readUtxos :: forall (m :: * -> *) a.
QueryHandlers m a
-> UnaryHandler m ReadUtxosRequest ReadUtxosResponse
readUtxos :: UnaryHandler m ReadUtxosRequest ReadUtxosResponse
readUtxos, UnaryHandler m SearchUtxosRequest SearchUtxosResponse
searchUtxos :: forall (m :: * -> *) a.
QueryHandlers m a
-> UnaryHandler m SearchUtxosRequest SearchUtxosResponse
searchUtxos :: UnaryHandler m SearchUtxosRequest SearchUtxosResponse
searchUtxos, ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse b
streamUtxos :: forall (m :: * -> *) a.
QueryHandlers m a
-> ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse a
streamUtxos :: ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse b
streamUtxos } =
  [ServiceHandler
readParamsSH, ServiceHandler
readUtxosSH, ServiceHandler
searchUtxosSH, ServiceHandler
streamUtxosSH ]
  where
    readParamsSH :: ServiceHandler
readParamsSH = (forall x. m x -> IO x)
-> RPC QueryService "readParams"
-> UnaryHandler m ReadParamsRequest ReadParamsResponse
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
forall (m :: * -> *) r i o.
(MonadIO m, GRPCInput r i, GRPCOutput r o, Show i, Show o) =>
(forall x. m x -> IO x)
-> r
-> UnaryHandler m i o
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
loggedUnary m x -> IO x
forall x. m x -> IO x
f (RPC QueryService "readParams"
forall s (m :: Symbol). RPC s m
RPC :: RPC QueryService "readParams") UnaryHandler m ReadParamsRequest ReadParamsResponse
readParams Maybe (UtxorpcServiceLogger m)
logger
    readUtxosSH :: ServiceHandler
readUtxosSH = (forall x. m x -> IO x)
-> RPC QueryService "readUtxos"
-> UnaryHandler m ReadUtxosRequest ReadUtxosResponse
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
forall (m :: * -> *) r i o.
(MonadIO m, GRPCInput r i, GRPCOutput r o, Show i, Show o) =>
(forall x. m x -> IO x)
-> r
-> UnaryHandler m i o
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
loggedUnary m x -> IO x
forall x. m x -> IO x
f (RPC QueryService "readUtxos"
forall s (m :: Symbol). RPC s m
RPC :: RPC QueryService "readUtxos") UnaryHandler m ReadUtxosRequest ReadUtxosResponse
readUtxos Maybe (UtxorpcServiceLogger m)
logger
    searchUtxosSH :: ServiceHandler
searchUtxosSH = (forall x. m x -> IO x)
-> RPC QueryService "searchUtxos"
-> UnaryHandler m SearchUtxosRequest SearchUtxosResponse
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
forall (m :: * -> *) r i o.
(MonadIO m, GRPCInput r i, GRPCOutput r o, Show i, Show o) =>
(forall x. m x -> IO x)
-> r
-> UnaryHandler m i o
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
loggedUnary m x -> IO x
forall x. m x -> IO x
f (RPC QueryService "searchUtxos"
forall s (m :: Symbol). RPC s m
RPC :: RPC QueryService "searchUtxos") UnaryHandler m SearchUtxosRequest SearchUtxosResponse
searchUtxos Maybe (UtxorpcServiceLogger m)
logger
    streamUtxosSH :: ServiceHandler
streamUtxosSH = (forall x. m x -> IO x)
-> RPC QueryService "streamUtxos"
-> ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse b
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
forall (m :: * -> *) r i o a.
(MonadIO m, GRPCInput r i, GRPCOutput r o, Show i, Show o) =>
(forall x. m x -> IO x)
-> r
-> ServerStreamHandler m i o a
-> Maybe (UtxorpcServiceLogger m)
-> ServiceHandler
loggedSStream m x -> IO x
forall x. m x -> IO x
f (RPC QueryService "streamUtxos"
forall s (m :: Symbol). RPC s m
RPC :: RPC QueryService "streamUtxos") ServerStreamHandler m ReadUtxosRequest ReadUtxosResponse b
streamUtxos Maybe (UtxorpcServiceLogger m)
logger