{-# LANGUAGE CPP           #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DataKinds     #-}
#if __GLASGOW_HASKELL__ < 800
{-# OPTIONS_GHC -fcontext-stack=26 #-}
#else
{-# OPTIONS_GHC -freduction-depth=0 #-}
#endif
--------------------------------------------------------------------------------
-- |
-- Module : Database.EventStore.Internal.Operation.ReadEvent.Message
-- Copyright : (C) 2015 Yorick Laupa
-- License : (see the file LICENSE)
--
-- Maintainer : Yorick Laupa <yo.eight@gmail.com>
-- Stability : provisional
-- Portability : non-portable
--
--------------------------------------------------------------------------------
module Database.EventStore.Internal.Operation.ReadEvent.Message where

--------------------------------------------------------------------------------
import Data.Int

--------------------------------------------------------------------------------
import Data.ProtocolBuffers

--------------------------------------------------------------------------------
import Database.EventStore.Internal.Prelude
import Database.EventStore.Internal.Types

--------------------------------------------------------------------------------
-- | Read event on a regular stream request.
data Request
    = Request
      { Request -> Required 1 (Value Text)
_streamId       :: Required 1 (Value Text)
      , Request -> Required 2 (Value Int64)
_eventNumber    :: Required 2 (Value Int64)
      , Request -> Required 3 (Value Bool)
_resolveLinkTos :: Required 3 (Value Bool)
      , Request -> Required 4 (Value Bool)
_requireMaster  :: Required 4 (Value Bool)
      }
    deriving (forall x. Rep Request x -> Request
forall x. Request -> Rep Request x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Request x -> Request
$cfrom :: forall x. Request -> Rep Request x
Generic, Int -> Request -> ShowS
[Request] -> ShowS
Request -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Request] -> ShowS
$cshowList :: [Request] -> ShowS
show :: Request -> String
$cshow :: Request -> String
showsPrec :: Int -> Request -> ShowS
$cshowsPrec :: Int -> Request -> ShowS
Show)

--------------------------------------------------------------------------------
instance Encode Request

--------------------------------------------------------------------------------
-- | 'Request' smart constructor.
newRequest :: Text -> Int64 -> Bool -> Bool -> Request
newRequest :: Text -> Int64 -> Bool -> Bool -> Request
newRequest Text
stream_id Int64
evt_num Bool
res_link_tos Bool
req_master =
    Request
    { _streamId :: Required 1 (Value Text)
_streamId       = forall a. HasField a => FieldType a -> a
putField Text
stream_id
    , _eventNumber :: Required 2 (Value Int64)
_eventNumber    = forall a. HasField a => FieldType a -> a
putField Int64
evt_num
    , _resolveLinkTos :: Required 3 (Value Bool)
_resolveLinkTos = forall a. HasField a => FieldType a -> a
putField Bool
res_link_tos
    , _requireMaster :: Required 4 (Value Bool)
_requireMaster  = forall a. HasField a => FieldType a -> a
putField Bool
req_master
    }

--------------------------------------------------------------------------------
-- | Enumeration representing the status of a single event read operation.
data Result
    = SUCCESS
    | NOT_FOUND
    | NO_STREAM
    | STREAM_DELETED
    | ERROR
    | ACCESS_DENIED
    deriving (Result -> Result -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Result -> Result -> Bool
$c/= :: Result -> Result -> Bool
== :: Result -> Result -> Bool
$c== :: Result -> Result -> Bool
Eq, Int -> Result
Result -> Int
Result -> [Result]
Result -> Result
Result -> Result -> [Result]
Result -> Result -> Result -> [Result]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Result -> Result -> Result -> [Result]
$cenumFromThenTo :: Result -> Result -> Result -> [Result]
enumFromTo :: Result -> Result -> [Result]
$cenumFromTo :: Result -> Result -> [Result]
enumFromThen :: Result -> Result -> [Result]
$cenumFromThen :: Result -> Result -> [Result]
enumFrom :: Result -> [Result]
$cenumFrom :: Result -> [Result]
fromEnum :: Result -> Int
$cfromEnum :: Result -> Int
toEnum :: Int -> Result
$ctoEnum :: Int -> Result
pred :: Result -> Result
$cpred :: Result -> Result
succ :: Result -> Result
$csucc :: Result -> Result
Enum, Int -> Result -> ShowS
[Result] -> ShowS
Result -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Result] -> ShowS
$cshowList :: [Result] -> ShowS
show :: Result -> String
$cshow :: Result -> String
showsPrec :: Int -> Result -> ShowS
$cshowsPrec :: Int -> Result -> ShowS
Show)

--------------------------------------------------------------------------------
-- | Read event on a regular stream response.
data Response
    = Response
      { Response -> Required 1 (Enumeration Result)
_result       :: Required 1 (Enumeration Result)
      , Response -> Required 2 (Message ResolvedIndexedEvent)
_indexedEvent :: Required 2 (Message ResolvedIndexedEvent)
      , Response -> Optional 3 (Value Text)
_error        :: Optional 3 (Value Text)
      }
    deriving (forall x. Rep Response x -> Response
forall x. Response -> Rep Response x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Response x -> Response
$cfrom :: forall x. Response -> Rep Response x
Generic, Int -> Response -> ShowS
[Response] -> ShowS
Response -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Response] -> ShowS
$cshowList :: [Response] -> ShowS
show :: Response -> String
$cshow :: Response -> String
showsPrec :: Int -> Response -> ShowS
$cshowsPrec :: Int -> Response -> ShowS
Show)

--------------------------------------------------------------------------------
instance Decode Response
instance Encode Response