module TD.Data.NotificationSettingsScope
  (NotificationSettingsScope(..)) where

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

-- | Describes the types of chats to which notification settings are relevant
data NotificationSettingsScope
  = NotificationSettingsScopePrivateChats -- ^ Notification settings applied to all private and secret chats when the corresponding chat setting has a default value
  | NotificationSettingsScopeGroupChats -- ^ Notification settings applied to all basic group and supergroup chats when the corresponding chat setting has a default value
  | NotificationSettingsScopeChannelChats -- ^ Notification settings applied to all channel chats when the corresponding chat setting has a default value
  deriving (NotificationSettingsScope -> NotificationSettingsScope -> Bool
(NotificationSettingsScope -> NotificationSettingsScope -> Bool)
-> (NotificationSettingsScope -> NotificationSettingsScope -> Bool)
-> Eq NotificationSettingsScope
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NotificationSettingsScope -> NotificationSettingsScope -> Bool
== :: NotificationSettingsScope -> NotificationSettingsScope -> Bool
$c/= :: NotificationSettingsScope -> NotificationSettingsScope -> Bool
/= :: NotificationSettingsScope -> NotificationSettingsScope -> Bool
Eq, Int -> NotificationSettingsScope -> ShowS
[NotificationSettingsScope] -> ShowS
NotificationSettingsScope -> String
(Int -> NotificationSettingsScope -> ShowS)
-> (NotificationSettingsScope -> String)
-> ([NotificationSettingsScope] -> ShowS)
-> Show NotificationSettingsScope
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NotificationSettingsScope -> ShowS
showsPrec :: Int -> NotificationSettingsScope -> ShowS
$cshow :: NotificationSettingsScope -> String
show :: NotificationSettingsScope -> String
$cshowList :: [NotificationSettingsScope] -> ShowS
showList :: [NotificationSettingsScope] -> ShowS
Show)

instance I.ShortShow NotificationSettingsScope where
  shortShow :: NotificationSettingsScope -> String
shortShow NotificationSettingsScope
NotificationSettingsScopePrivateChats
      = String
"NotificationSettingsScopePrivateChats"
  shortShow NotificationSettingsScope
NotificationSettingsScopeGroupChats
      = String
"NotificationSettingsScopeGroupChats"
  shortShow NotificationSettingsScope
NotificationSettingsScopeChannelChats
      = String
"NotificationSettingsScopeChannelChats"

instance AT.FromJSON NotificationSettingsScope where
  parseJSON :: Value -> Parser NotificationSettingsScope
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
"notificationSettingsScopePrivateChats" -> NotificationSettingsScope -> Parser NotificationSettingsScope
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure NotificationSettingsScope
NotificationSettingsScopePrivateChats
      String
"notificationSettingsScopeGroupChats"   -> NotificationSettingsScope -> Parser NotificationSettingsScope
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure NotificationSettingsScope
NotificationSettingsScopeGroupChats
      String
"notificationSettingsScopeChannelChats" -> NotificationSettingsScope -> Parser NotificationSettingsScope
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure NotificationSettingsScope
NotificationSettingsScopeChannelChats
      String
_                                       -> Parser NotificationSettingsScope
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser NotificationSettingsScope
forall a. Monoid a => a
mempty

instance AT.ToJSON NotificationSettingsScope where
  toJSON :: NotificationSettingsScope -> Value
toJSON NotificationSettingsScope
NotificationSettingsScopePrivateChats
      = [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
"notificationSettingsScopePrivateChats"
        ]
  toJSON NotificationSettingsScope
NotificationSettingsScopeGroupChats
      = [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
"notificationSettingsScopeGroupChats"
        ]
  toJSON NotificationSettingsScope
NotificationSettingsScopeChannelChats
      = [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
"notificationSettingsScopeChannelChats"
        ]