module TD.Data.UserPrivacySettingRules
( UserPrivacySettingRules(..)
, defaultUserPrivacySettingRules
) 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.UserPrivacySettingRule as UserPrivacySettingRule
data UserPrivacySettingRules
= UserPrivacySettingRules
{ UserPrivacySettingRules -> Maybe [UserPrivacySettingRule]
rules :: Maybe [UserPrivacySettingRule.UserPrivacySettingRule]
}
deriving (UserPrivacySettingRules -> UserPrivacySettingRules -> Bool
(UserPrivacySettingRules -> UserPrivacySettingRules -> Bool)
-> (UserPrivacySettingRules -> UserPrivacySettingRules -> Bool)
-> Eq UserPrivacySettingRules
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserPrivacySettingRules -> UserPrivacySettingRules -> Bool
== :: UserPrivacySettingRules -> UserPrivacySettingRules -> Bool
$c/= :: UserPrivacySettingRules -> UserPrivacySettingRules -> Bool
/= :: UserPrivacySettingRules -> UserPrivacySettingRules -> Bool
Eq, Int -> UserPrivacySettingRules -> ShowS
[UserPrivacySettingRules] -> ShowS
UserPrivacySettingRules -> String
(Int -> UserPrivacySettingRules -> ShowS)
-> (UserPrivacySettingRules -> String)
-> ([UserPrivacySettingRules] -> ShowS)
-> Show UserPrivacySettingRules
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserPrivacySettingRules -> ShowS
showsPrec :: Int -> UserPrivacySettingRules -> ShowS
$cshow :: UserPrivacySettingRules -> String
show :: UserPrivacySettingRules -> String
$cshowList :: [UserPrivacySettingRules] -> ShowS
showList :: [UserPrivacySettingRules] -> ShowS
Show)
instance I.ShortShow UserPrivacySettingRules where
shortShow :: UserPrivacySettingRules -> String
shortShow UserPrivacySettingRules
{ rules :: UserPrivacySettingRules -> Maybe [UserPrivacySettingRule]
rules = Maybe [UserPrivacySettingRule]
rules_
}
= String
"UserPrivacySettingRules"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"rules" String -> Maybe [UserPrivacySettingRule] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [UserPrivacySettingRule]
rules_
]
instance AT.FromJSON UserPrivacySettingRules where
parseJSON :: Value -> Parser UserPrivacySettingRules
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
"userPrivacySettingRules" -> Value -> Parser UserPrivacySettingRules
parseUserPrivacySettingRules Value
v
String
_ -> Parser UserPrivacySettingRules
forall a. Monoid a => a
mempty
where
parseUserPrivacySettingRules :: A.Value -> AT.Parser UserPrivacySettingRules
parseUserPrivacySettingRules :: Value -> Parser UserPrivacySettingRules
parseUserPrivacySettingRules = String
-> (Object -> Parser UserPrivacySettingRules)
-> Value
-> Parser UserPrivacySettingRules
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserPrivacySettingRules" ((Object -> Parser UserPrivacySettingRules)
-> Value -> Parser UserPrivacySettingRules)
-> (Object -> Parser UserPrivacySettingRules)
-> Value
-> Parser UserPrivacySettingRules
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [UserPrivacySettingRule]
rules_ <- Object
o Object -> Key -> Parser (Maybe [UserPrivacySettingRule])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"rules"
UserPrivacySettingRules -> Parser UserPrivacySettingRules
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserPrivacySettingRules -> Parser UserPrivacySettingRules)
-> UserPrivacySettingRules -> Parser UserPrivacySettingRules
forall a b. (a -> b) -> a -> b
$ UserPrivacySettingRules
{ rules :: Maybe [UserPrivacySettingRule]
rules = Maybe [UserPrivacySettingRule]
rules_
}
parseJSON Value
_ = Parser UserPrivacySettingRules
forall a. Monoid a => a
mempty
instance AT.ToJSON UserPrivacySettingRules where
toJSON :: UserPrivacySettingRules -> Value
toJSON UserPrivacySettingRules
{ rules :: UserPrivacySettingRules -> Maybe [UserPrivacySettingRule]
rules = Maybe [UserPrivacySettingRule]
rules_
}
= [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
"userPrivacySettingRules"
, Key
"rules" Key -> Maybe [UserPrivacySettingRule] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [UserPrivacySettingRule]
rules_
]
defaultUserPrivacySettingRules :: UserPrivacySettingRules
defaultUserPrivacySettingRules :: UserPrivacySettingRules
defaultUserPrivacySettingRules =
UserPrivacySettingRules
{ rules :: Maybe [UserPrivacySettingRule]
rules = Maybe [UserPrivacySettingRule]
forall a. Maybe a
Nothing
}