module TD.Data.PushReceiverId
(PushReceiverId(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data PushReceiverId
= PushReceiverId
{ PushReceiverId -> Maybe Int
_id :: Maybe Int
}
deriving (PushReceiverId -> PushReceiverId -> Bool
(PushReceiverId -> PushReceiverId -> Bool)
-> (PushReceiverId -> PushReceiverId -> Bool) -> Eq PushReceiverId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PushReceiverId -> PushReceiverId -> Bool
== :: PushReceiverId -> PushReceiverId -> Bool
$c/= :: PushReceiverId -> PushReceiverId -> Bool
/= :: PushReceiverId -> PushReceiverId -> Bool
Eq, Int -> PushReceiverId -> ShowS
[PushReceiverId] -> ShowS
PushReceiverId -> String
(Int -> PushReceiverId -> ShowS)
-> (PushReceiverId -> String)
-> ([PushReceiverId] -> ShowS)
-> Show PushReceiverId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PushReceiverId -> ShowS
showsPrec :: Int -> PushReceiverId -> ShowS
$cshow :: PushReceiverId -> String
show :: PushReceiverId -> String
$cshowList :: [PushReceiverId] -> ShowS
showList :: [PushReceiverId] -> ShowS
Show)
instance I.ShortShow PushReceiverId where
shortShow :: PushReceiverId -> String
shortShow PushReceiverId
{ _id :: PushReceiverId -> Maybe Int
_id = Maybe Int
_id_
}
= String
"PushReceiverId"
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_
]
instance AT.FromJSON PushReceiverId where
parseJSON :: Value -> Parser PushReceiverId
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
"pushReceiverId" -> Value -> Parser PushReceiverId
parsePushReceiverId Value
v
String
_ -> Parser PushReceiverId
forall a. Monoid a => a
mempty
where
parsePushReceiverId :: A.Value -> AT.Parser PushReceiverId
parsePushReceiverId :: Value -> Parser PushReceiverId
parsePushReceiverId = String
-> (Object -> Parser PushReceiverId)
-> Value
-> Parser PushReceiverId
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PushReceiverId" ((Object -> Parser PushReceiverId)
-> Value -> Parser PushReceiverId)
-> (Object -> Parser PushReceiverId)
-> Value
-> Parser PushReceiverId
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
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
"id"
PushReceiverId -> Parser PushReceiverId
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PushReceiverId -> Parser PushReceiverId)
-> PushReceiverId -> Parser PushReceiverId
forall a b. (a -> b) -> a -> b
$ PushReceiverId
{ _id :: Maybe Int
_id = Maybe Int
_id_
}
parseJSON Value
_ = Parser PushReceiverId
forall a. Monoid a => a
mempty