module TD.Data.SecretChat
(SecretChat(..)) 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.SecretChatState as SecretChatState
import qualified Data.ByteString as BS
data SecretChat
= SecretChat
{ SecretChat -> Maybe Int
_id :: Maybe Int
, SecretChat -> Maybe Int
user_id :: Maybe Int
, SecretChat -> Maybe SecretChatState
state :: Maybe SecretChatState.SecretChatState
, SecretChat -> Maybe Bool
is_outbound :: Maybe Bool
, SecretChat -> Maybe ByteString
key_hash :: Maybe BS.ByteString
, SecretChat -> Maybe Int
layer :: Maybe Int
}
deriving (SecretChat -> SecretChat -> Bool
(SecretChat -> SecretChat -> Bool)
-> (SecretChat -> SecretChat -> Bool) -> Eq SecretChat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SecretChat -> SecretChat -> Bool
== :: SecretChat -> SecretChat -> Bool
$c/= :: SecretChat -> SecretChat -> Bool
/= :: SecretChat -> SecretChat -> Bool
Eq, Int -> SecretChat -> ShowS
[SecretChat] -> ShowS
SecretChat -> String
(Int -> SecretChat -> ShowS)
-> (SecretChat -> String)
-> ([SecretChat] -> ShowS)
-> Show SecretChat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SecretChat -> ShowS
showsPrec :: Int -> SecretChat -> ShowS
$cshow :: SecretChat -> String
show :: SecretChat -> String
$cshowList :: [SecretChat] -> ShowS
showList :: [SecretChat] -> ShowS
Show)
instance I.ShortShow SecretChat where
shortShow :: SecretChat -> String
shortShow SecretChat
{ _id :: SecretChat -> Maybe Int
_id = Maybe Int
_id_
, user_id :: SecretChat -> Maybe Int
user_id = Maybe Int
user_id_
, state :: SecretChat -> Maybe SecretChatState
state = Maybe SecretChatState
state_
, is_outbound :: SecretChat -> Maybe Bool
is_outbound = Maybe Bool
is_outbound_
, key_hash :: SecretChat -> Maybe ByteString
key_hash = Maybe ByteString
key_hash_
, layer :: SecretChat -> Maybe Int
layer = Maybe Int
layer_
}
= String
"SecretChat"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
, String
"state" String -> Maybe SecretChatState -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe SecretChatState
state_
, String
"is_outbound" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_outbound_
, String
"key_hash" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
key_hash_
, String
"layer" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
layer_
]
instance AT.FromJSON SecretChat where
parseJSON :: Value -> Parser SecretChat
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
"secretChat" -> Value -> Parser SecretChat
parseSecretChat Value
v
String
_ -> Parser SecretChat
forall a. Monoid a => a
mempty
where
parseSecretChat :: A.Value -> AT.Parser SecretChat
parseSecretChat :: Value -> Parser SecretChat
parseSecretChat = String
-> (Object -> Parser SecretChat) -> Value -> Parser SecretChat
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"SecretChat" ((Object -> Parser SecretChat) -> Value -> Parser SecretChat)
-> (Object -> Parser SecretChat) -> Value -> Parser SecretChat
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe Int
user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"user_id"
Maybe SecretChatState
state_ <- Object
o Object -> Key -> Parser (Maybe SecretChatState)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"state"
Maybe Bool
is_outbound_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_outbound"
Maybe ByteString
key_hash_ <- (String -> ByteString) -> Maybe String -> Maybe ByteString
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ByteString
I.readBytes (Maybe String -> Maybe ByteString)
-> Parser (Maybe String) -> Parser (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"key_hash"
Maybe Int
layer_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"layer"
SecretChat -> Parser SecretChat
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SecretChat -> Parser SecretChat)
-> SecretChat -> Parser SecretChat
forall a b. (a -> b) -> a -> b
$ SecretChat
{ _id :: Maybe Int
_id = Maybe Int
_id_
, user_id :: Maybe Int
user_id = Maybe Int
user_id_
, state :: Maybe SecretChatState
state = Maybe SecretChatState
state_
, is_outbound :: Maybe Bool
is_outbound = Maybe Bool
is_outbound_
, key_hash :: Maybe ByteString
key_hash = Maybe ByteString
key_hash_
, layer :: Maybe Int
layer = Maybe Int
layer_
}
parseJSON Value
_ = Parser SecretChat
forall a. Monoid a => a
mempty