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