module Hasura.RQL.Types.Subscription
  ( CursorOrdering (..),
    SubscriptionType (..),
  )
where

import Data.Aeson (ToJSON (..))
import Hasura.Prelude

-- | CursorOrdering is used in the streaming subscriptions to specify how to order the cursor.
data CursorOrdering = COAscending | CODescending deriving (Int -> CursorOrdering -> ShowS
[CursorOrdering] -> ShowS
CursorOrdering -> String
(Int -> CursorOrdering -> ShowS)
-> (CursorOrdering -> String)
-> ([CursorOrdering] -> ShowS)
-> Show CursorOrdering
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CursorOrdering -> ShowS
showsPrec :: Int -> CursorOrdering -> ShowS
$cshow :: CursorOrdering -> String
show :: CursorOrdering -> String
$cshowList :: [CursorOrdering] -> ShowS
showList :: [CursorOrdering] -> ShowS
Show, CursorOrdering -> CursorOrdering -> Bool
(CursorOrdering -> CursorOrdering -> Bool)
-> (CursorOrdering -> CursorOrdering -> Bool) -> Eq CursorOrdering
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CursorOrdering -> CursorOrdering -> Bool
== :: CursorOrdering -> CursorOrdering -> Bool
$c/= :: CursorOrdering -> CursorOrdering -> Bool
/= :: CursorOrdering -> CursorOrdering -> Bool
Eq, (forall x. CursorOrdering -> Rep CursorOrdering x)
-> (forall x. Rep CursorOrdering x -> CursorOrdering)
-> Generic CursorOrdering
forall x. Rep CursorOrdering x -> CursorOrdering
forall x. CursorOrdering -> Rep CursorOrdering x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CursorOrdering -> Rep CursorOrdering x
from :: forall x. CursorOrdering -> Rep CursorOrdering x
$cto :: forall x. Rep CursorOrdering x -> CursorOrdering
to :: forall x. Rep CursorOrdering x -> CursorOrdering
Generic)

instance Hashable CursorOrdering

data SubscriptionType = Streaming | LiveQuery deriving (Int -> SubscriptionType -> ShowS
[SubscriptionType] -> ShowS
SubscriptionType -> String
(Int -> SubscriptionType -> ShowS)
-> (SubscriptionType -> String)
-> ([SubscriptionType] -> ShowS)
-> Show SubscriptionType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SubscriptionType -> ShowS
showsPrec :: Int -> SubscriptionType -> ShowS
$cshow :: SubscriptionType -> String
show :: SubscriptionType -> String
$cshowList :: [SubscriptionType] -> ShowS
showList :: [SubscriptionType] -> ShowS
Show, SubscriptionType -> SubscriptionType -> Bool
(SubscriptionType -> SubscriptionType -> Bool)
-> (SubscriptionType -> SubscriptionType -> Bool)
-> Eq SubscriptionType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SubscriptionType -> SubscriptionType -> Bool
== :: SubscriptionType -> SubscriptionType -> Bool
$c/= :: SubscriptionType -> SubscriptionType -> Bool
/= :: SubscriptionType -> SubscriptionType -> Bool
Eq, (forall x. SubscriptionType -> Rep SubscriptionType x)
-> (forall x. Rep SubscriptionType x -> SubscriptionType)
-> Generic SubscriptionType
forall x. Rep SubscriptionType x -> SubscriptionType
forall x. SubscriptionType -> Rep SubscriptionType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SubscriptionType -> Rep SubscriptionType x
from :: forall x. SubscriptionType -> Rep SubscriptionType x
$cto :: forall x. Rep SubscriptionType x -> SubscriptionType
to :: forall x. Rep SubscriptionType x -> SubscriptionType
Generic)

instance ToJSON SubscriptionType where
  toJSON :: SubscriptionType -> Value
toJSON = \case
    SubscriptionType
Streaming -> Value
"streaming"
    SubscriptionType
LiveQuery -> Value
"live-query"