module TD.Data.AutosaveSettings
(AutosaveSettings(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.ScopeAutosaveSettings as ScopeAutosaveSettings
import qualified TD.Data.AutosaveSettingsException as AutosaveSettingsException
data AutosaveSettings
= AutosaveSettings
{ AutosaveSettings -> Maybe ScopeAutosaveSettings
private_chat_settings :: Maybe ScopeAutosaveSettings.ScopeAutosaveSettings
, AutosaveSettings -> Maybe ScopeAutosaveSettings
group_settings :: Maybe ScopeAutosaveSettings.ScopeAutosaveSettings
, AutosaveSettings -> Maybe ScopeAutosaveSettings
channel_settings :: Maybe ScopeAutosaveSettings.ScopeAutosaveSettings
, AutosaveSettings -> Maybe [AutosaveSettingsException]
exceptions :: Maybe [AutosaveSettingsException.AutosaveSettingsException]
}
deriving (AutosaveSettings -> AutosaveSettings -> Bool
(AutosaveSettings -> AutosaveSettings -> Bool)
-> (AutosaveSettings -> AutosaveSettings -> Bool)
-> Eq AutosaveSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AutosaveSettings -> AutosaveSettings -> Bool
== :: AutosaveSettings -> AutosaveSettings -> Bool
$c/= :: AutosaveSettings -> AutosaveSettings -> Bool
/= :: AutosaveSettings -> AutosaveSettings -> Bool
Eq, Int -> AutosaveSettings -> ShowS
[AutosaveSettings] -> ShowS
AutosaveSettings -> String
(Int -> AutosaveSettings -> ShowS)
-> (AutosaveSettings -> String)
-> ([AutosaveSettings] -> ShowS)
-> Show AutosaveSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AutosaveSettings -> ShowS
showsPrec :: Int -> AutosaveSettings -> ShowS
$cshow :: AutosaveSettings -> String
show :: AutosaveSettings -> String
$cshowList :: [AutosaveSettings] -> ShowS
showList :: [AutosaveSettings] -> ShowS
Show)
instance I.ShortShow AutosaveSettings where
shortShow :: AutosaveSettings -> String
shortShow AutosaveSettings
{ private_chat_settings :: AutosaveSettings -> Maybe ScopeAutosaveSettings
private_chat_settings = Maybe ScopeAutosaveSettings
private_chat_settings_
, group_settings :: AutosaveSettings -> Maybe ScopeAutosaveSettings
group_settings = Maybe ScopeAutosaveSettings
group_settings_
, channel_settings :: AutosaveSettings -> Maybe ScopeAutosaveSettings
channel_settings = Maybe ScopeAutosaveSettings
channel_settings_
, exceptions :: AutosaveSettings -> Maybe [AutosaveSettingsException]
exceptions = Maybe [AutosaveSettingsException]
exceptions_
}
= String
"AutosaveSettings"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"private_chat_settings" String -> Maybe ScopeAutosaveSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ScopeAutosaveSettings
private_chat_settings_
, String
"group_settings" String -> Maybe ScopeAutosaveSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ScopeAutosaveSettings
group_settings_
, String
"channel_settings" String -> Maybe ScopeAutosaveSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ScopeAutosaveSettings
channel_settings_
, String
"exceptions" String -> Maybe [AutosaveSettingsException] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [AutosaveSettingsException]
exceptions_
]
instance AT.FromJSON AutosaveSettings where
parseJSON :: Value -> Parser AutosaveSettings
parseJSON v :: Value
v@(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
"autosaveSettings" -> Value -> Parser AutosaveSettings
parseAutosaveSettings Value
v
String
_ -> Parser AutosaveSettings
forall a. Monoid a => a
mempty
where
parseAutosaveSettings :: A.Value -> AT.Parser AutosaveSettings
parseAutosaveSettings :: Value -> Parser AutosaveSettings
parseAutosaveSettings = String
-> (Object -> Parser AutosaveSettings)
-> Value
-> Parser AutosaveSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AutosaveSettings" ((Object -> Parser AutosaveSettings)
-> Value -> Parser AutosaveSettings)
-> (Object -> Parser AutosaveSettings)
-> Value
-> Parser AutosaveSettings
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ScopeAutosaveSettings
private_chat_settings_ <- Object
o Object -> Key -> Parser (Maybe ScopeAutosaveSettings)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"private_chat_settings"
Maybe ScopeAutosaveSettings
group_settings_ <- Object
o Object -> Key -> Parser (Maybe ScopeAutosaveSettings)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"group_settings"
Maybe ScopeAutosaveSettings
channel_settings_ <- Object
o Object -> Key -> Parser (Maybe ScopeAutosaveSettings)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"channel_settings"
Maybe [AutosaveSettingsException]
exceptions_ <- Object
o Object -> Key -> Parser (Maybe [AutosaveSettingsException])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"exceptions"
AutosaveSettings -> Parser AutosaveSettings
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AutosaveSettings -> Parser AutosaveSettings)
-> AutosaveSettings -> Parser AutosaveSettings
forall a b. (a -> b) -> a -> b
$ AutosaveSettings
{ private_chat_settings :: Maybe ScopeAutosaveSettings
private_chat_settings = Maybe ScopeAutosaveSettings
private_chat_settings_
, group_settings :: Maybe ScopeAutosaveSettings
group_settings = Maybe ScopeAutosaveSettings
group_settings_
, channel_settings :: Maybe ScopeAutosaveSettings
channel_settings = Maybe ScopeAutosaveSettings
channel_settings_
, exceptions :: Maybe [AutosaveSettingsException]
exceptions = Maybe [AutosaveSettingsException]
exceptions_
}
parseJSON Value
_ = Parser AutosaveSettings
forall a. Monoid a => a
mempty