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