module TD.Data.UnconfirmedSession
(UnconfirmedSession(..)) 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 UnconfirmedSession
= UnconfirmedSession
{ UnconfirmedSession -> Maybe Int
_id :: Maybe Int
, UnconfirmedSession -> Maybe Int
log_in_date :: Maybe Int
, UnconfirmedSession -> Maybe Text
device_model :: Maybe T.Text
, UnconfirmedSession -> Maybe Text
location :: Maybe T.Text
}
deriving (UnconfirmedSession -> UnconfirmedSession -> Bool
(UnconfirmedSession -> UnconfirmedSession -> Bool)
-> (UnconfirmedSession -> UnconfirmedSession -> Bool)
-> Eq UnconfirmedSession
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UnconfirmedSession -> UnconfirmedSession -> Bool
== :: UnconfirmedSession -> UnconfirmedSession -> Bool
$c/= :: UnconfirmedSession -> UnconfirmedSession -> Bool
/= :: UnconfirmedSession -> UnconfirmedSession -> Bool
Eq, Int -> UnconfirmedSession -> ShowS
[UnconfirmedSession] -> ShowS
UnconfirmedSession -> String
(Int -> UnconfirmedSession -> ShowS)
-> (UnconfirmedSession -> String)
-> ([UnconfirmedSession] -> ShowS)
-> Show UnconfirmedSession
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UnconfirmedSession -> ShowS
showsPrec :: Int -> UnconfirmedSession -> ShowS
$cshow :: UnconfirmedSession -> String
show :: UnconfirmedSession -> String
$cshowList :: [UnconfirmedSession] -> ShowS
showList :: [UnconfirmedSession] -> ShowS
Show)
instance I.ShortShow UnconfirmedSession where
shortShow :: UnconfirmedSession -> String
shortShow UnconfirmedSession
{ _id :: UnconfirmedSession -> Maybe Int
_id = Maybe Int
_id_
, log_in_date :: UnconfirmedSession -> Maybe Int
log_in_date = Maybe Int
log_in_date_
, device_model :: UnconfirmedSession -> Maybe Text
device_model = Maybe Text
device_model_
, location :: UnconfirmedSession -> Maybe Text
location = Maybe Text
location_
}
= String
"UnconfirmedSession"
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
"log_in_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
log_in_date_
, String
"device_model" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
device_model_
, String
"location" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
location_
]
instance AT.FromJSON UnconfirmedSession where
parseJSON :: Value -> Parser UnconfirmedSession
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
"unconfirmedSession" -> Value -> Parser UnconfirmedSession
parseUnconfirmedSession Value
v
String
_ -> Parser UnconfirmedSession
forall a. Monoid a => a
mempty
where
parseUnconfirmedSession :: A.Value -> AT.Parser UnconfirmedSession
parseUnconfirmedSession :: Value -> Parser UnconfirmedSession
parseUnconfirmedSession = String
-> (Object -> Parser UnconfirmedSession)
-> Value
-> Parser UnconfirmedSession
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UnconfirmedSession" ((Object -> Parser UnconfirmedSession)
-> Value -> Parser UnconfirmedSession)
-> (Object -> Parser UnconfirmedSession)
-> Value
-> Parser UnconfirmedSession
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"
Maybe Int
log_in_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"log_in_date"
Maybe Text
device_model_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"device_model"
Maybe Text
location_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"location"
UnconfirmedSession -> Parser UnconfirmedSession
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UnconfirmedSession -> Parser UnconfirmedSession)
-> UnconfirmedSession -> Parser UnconfirmedSession
forall a b. (a -> b) -> a -> b
$ UnconfirmedSession
{ _id :: Maybe Int
_id = Maybe Int
_id_
, log_in_date :: Maybe Int
log_in_date = Maybe Int
log_in_date_
, device_model :: Maybe Text
device_model = Maybe Text
device_model_
, location :: Maybe Text
location = Maybe Text
location_
}
parseJSON Value
_ = Parser UnconfirmedSession
forall a. Monoid a => a
mempty