module TD.Data.ReactionNotificationSource
  (ReactionNotificationSource(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

-- | Describes sources of reactions for which notifications will be shown
data ReactionNotificationSource
  = ReactionNotificationSourceNone -- ^ Notifications for reactions are disabled
  | ReactionNotificationSourceContacts -- ^ Notifications for reactions are shown only for reactions from contacts
  | ReactionNotificationSourceAll -- ^ Notifications for reactions are shown for all reactions
  deriving (ReactionNotificationSource -> ReactionNotificationSource -> Bool
(ReactionNotificationSource -> ReactionNotificationSource -> Bool)
-> (ReactionNotificationSource
    -> ReactionNotificationSource -> Bool)
-> Eq ReactionNotificationSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReactionNotificationSource -> ReactionNotificationSource -> Bool
== :: ReactionNotificationSource -> ReactionNotificationSource -> Bool
$c/= :: ReactionNotificationSource -> ReactionNotificationSource -> Bool
/= :: ReactionNotificationSource -> ReactionNotificationSource -> Bool
Eq, Int -> ReactionNotificationSource -> ShowS
[ReactionNotificationSource] -> ShowS
ReactionNotificationSource -> String
(Int -> ReactionNotificationSource -> ShowS)
-> (ReactionNotificationSource -> String)
-> ([ReactionNotificationSource] -> ShowS)
-> Show ReactionNotificationSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReactionNotificationSource -> ShowS
showsPrec :: Int -> ReactionNotificationSource -> ShowS
$cshow :: ReactionNotificationSource -> String
show :: ReactionNotificationSource -> String
$cshowList :: [ReactionNotificationSource] -> ShowS
showList :: [ReactionNotificationSource] -> ShowS
Show)

instance I.ShortShow ReactionNotificationSource where
  shortShow :: ReactionNotificationSource -> String
shortShow ReactionNotificationSource
ReactionNotificationSourceNone
      = String
"ReactionNotificationSourceNone"
  shortShow ReactionNotificationSource
ReactionNotificationSourceContacts
      = String
"ReactionNotificationSourceContacts"
  shortShow ReactionNotificationSource
ReactionNotificationSourceAll
      = String
"ReactionNotificationSourceAll"

instance AT.FromJSON ReactionNotificationSource where
  parseJSON :: Value -> Parser ReactionNotificationSource
parseJSON (AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"reactionNotificationSourceNone"     -> ReactionNotificationSource -> Parser ReactionNotificationSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReactionNotificationSource
ReactionNotificationSourceNone
      String
"reactionNotificationSourceContacts" -> ReactionNotificationSource -> Parser ReactionNotificationSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReactionNotificationSource
ReactionNotificationSourceContacts
      String
"reactionNotificationSourceAll"      -> ReactionNotificationSource -> Parser ReactionNotificationSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReactionNotificationSource
ReactionNotificationSourceAll
      String
_                                    -> Parser ReactionNotificationSource
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser ReactionNotificationSource
forall a. Monoid a => a
mempty

instance AT.ToJSON ReactionNotificationSource where
  toJSON :: ReactionNotificationSource -> Value
toJSON ReactionNotificationSource
ReactionNotificationSourceNone
      = [Pair] -> Value
A.object
        [ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"reactionNotificationSourceNone"
        ]
  toJSON ReactionNotificationSource
ReactionNotificationSourceContacts
      = [Pair] -> Value
A.object
        [ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"reactionNotificationSourceContacts"
        ]
  toJSON ReactionNotificationSource
ReactionNotificationSourceAll
      = [Pair] -> Value
A.object
        [ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"reactionNotificationSourceAll"
        ]