module TD.Data.RestrictionInfo
(RestrictionInfo(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
data RestrictionInfo
= RestrictionInfo
{ RestrictionInfo -> Maybe Text
restriction_reason :: Maybe T.Text
, RestrictionInfo -> Maybe Bool
has_sensitive_content :: Maybe Bool
}
deriving (RestrictionInfo -> RestrictionInfo -> Bool
(RestrictionInfo -> RestrictionInfo -> Bool)
-> (RestrictionInfo -> RestrictionInfo -> Bool)
-> Eq RestrictionInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RestrictionInfo -> RestrictionInfo -> Bool
== :: RestrictionInfo -> RestrictionInfo -> Bool
$c/= :: RestrictionInfo -> RestrictionInfo -> Bool
/= :: RestrictionInfo -> RestrictionInfo -> Bool
Eq, Int -> RestrictionInfo -> ShowS
[RestrictionInfo] -> ShowS
RestrictionInfo -> String
(Int -> RestrictionInfo -> ShowS)
-> (RestrictionInfo -> String)
-> ([RestrictionInfo] -> ShowS)
-> Show RestrictionInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RestrictionInfo -> ShowS
showsPrec :: Int -> RestrictionInfo -> ShowS
$cshow :: RestrictionInfo -> String
show :: RestrictionInfo -> String
$cshowList :: [RestrictionInfo] -> ShowS
showList :: [RestrictionInfo] -> ShowS
Show)
instance I.ShortShow RestrictionInfo where
shortShow :: RestrictionInfo -> String
shortShow RestrictionInfo
{ restriction_reason :: RestrictionInfo -> Maybe Text
restriction_reason = Maybe Text
restriction_reason_
, has_sensitive_content :: RestrictionInfo -> Maybe Bool
has_sensitive_content = Maybe Bool
has_sensitive_content_
}
= String
"RestrictionInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"restriction_reason" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
restriction_reason_
, String
"has_sensitive_content" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_sensitive_content_
]
instance AT.FromJSON RestrictionInfo where
parseJSON :: Value -> Parser RestrictionInfo
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
"restrictionInfo" -> Value -> Parser RestrictionInfo
parseRestrictionInfo Value
v
String
_ -> Parser RestrictionInfo
forall a. Monoid a => a
mempty
where
parseRestrictionInfo :: A.Value -> AT.Parser RestrictionInfo
parseRestrictionInfo :: Value -> Parser RestrictionInfo
parseRestrictionInfo = String
-> (Object -> Parser RestrictionInfo)
-> Value
-> Parser RestrictionInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RestrictionInfo" ((Object -> Parser RestrictionInfo)
-> Value -> Parser RestrictionInfo)
-> (Object -> Parser RestrictionInfo)
-> Value
-> Parser RestrictionInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
restriction_reason_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"restriction_reason"
Maybe Bool
has_sensitive_content_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"has_sensitive_content"
RestrictionInfo -> Parser RestrictionInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RestrictionInfo -> Parser RestrictionInfo)
-> RestrictionInfo -> Parser RestrictionInfo
forall a b. (a -> b) -> a -> b
$ RestrictionInfo
{ restriction_reason :: Maybe Text
restriction_reason = Maybe Text
restriction_reason_
, has_sensitive_content :: Maybe Bool
has_sensitive_content = Maybe Bool
has_sensitive_content_
}
parseJSON Value
_ = Parser RestrictionInfo
forall a. Monoid a => a
mempty