module TD.Data.Session
(Session(..)) 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.SessionType as SessionType
import qualified Data.Text as T
data Session
= Session
{ Session -> Maybe Int
_id :: Maybe Int
, Session -> Maybe Bool
is_current :: Maybe Bool
, Session -> Maybe Bool
is_password_pending :: Maybe Bool
, Session -> Maybe Bool
is_unconfirmed :: Maybe Bool
, Session -> Maybe Bool
can_accept_secret_chats :: Maybe Bool
, Session -> Maybe Bool
can_accept_calls :: Maybe Bool
, Session -> Maybe SessionType
_type :: Maybe SessionType.SessionType
, Session -> Maybe Int
api_id :: Maybe Int
, Session -> Maybe Text
application_name :: Maybe T.Text
, Session -> Maybe Text
application_version :: Maybe T.Text
, Session -> Maybe Bool
is_official_application :: Maybe Bool
, Session -> Maybe Text
device_model :: Maybe T.Text
, Session -> Maybe Text
platform :: Maybe T.Text
, Session -> Maybe Text
system_version :: Maybe T.Text
, Session -> Maybe Int
log_in_date :: Maybe Int
, Session -> Maybe Int
last_active_date :: Maybe Int
, Session -> Maybe Text
ip_address :: Maybe T.Text
, Session -> Maybe Text
location :: Maybe T.Text
}
deriving (Session -> Session -> Bool
(Session -> Session -> Bool)
-> (Session -> Session -> Bool) -> Eq Session
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Session -> Session -> Bool
== :: Session -> Session -> Bool
$c/= :: Session -> Session -> Bool
/= :: Session -> Session -> Bool
Eq, Int -> Session -> ShowS
[Session] -> ShowS
Session -> String
(Int -> Session -> ShowS)
-> (Session -> String) -> ([Session] -> ShowS) -> Show Session
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Session -> ShowS
showsPrec :: Int -> Session -> ShowS
$cshow :: Session -> String
show :: Session -> String
$cshowList :: [Session] -> ShowS
showList :: [Session] -> ShowS
Show)
instance I.ShortShow Session where
shortShow :: Session -> String
shortShow Session
{ _id :: Session -> Maybe Int
_id = Maybe Int
_id_
, is_current :: Session -> Maybe Bool
is_current = Maybe Bool
is_current_
, is_password_pending :: Session -> Maybe Bool
is_password_pending = Maybe Bool
is_password_pending_
, is_unconfirmed :: Session -> Maybe Bool
is_unconfirmed = Maybe Bool
is_unconfirmed_
, can_accept_secret_chats :: Session -> Maybe Bool
can_accept_secret_chats = Maybe Bool
can_accept_secret_chats_
, can_accept_calls :: Session -> Maybe Bool
can_accept_calls = Maybe Bool
can_accept_calls_
, _type :: Session -> Maybe SessionType
_type = Maybe SessionType
_type_
, api_id :: Session -> Maybe Int
api_id = Maybe Int
api_id_
, application_name :: Session -> Maybe Text
application_name = Maybe Text
application_name_
, application_version :: Session -> Maybe Text
application_version = Maybe Text
application_version_
, is_official_application :: Session -> Maybe Bool
is_official_application = Maybe Bool
is_official_application_
, device_model :: Session -> Maybe Text
device_model = Maybe Text
device_model_
, platform :: Session -> Maybe Text
platform = Maybe Text
platform_
, system_version :: Session -> Maybe Text
system_version = Maybe Text
system_version_
, log_in_date :: Session -> Maybe Int
log_in_date = Maybe Int
log_in_date_
, last_active_date :: Session -> Maybe Int
last_active_date = Maybe Int
last_active_date_
, ip_address :: Session -> Maybe Text
ip_address = Maybe Text
ip_address_
, location :: Session -> Maybe Text
location = Maybe Text
location_
}
= String
"Session"
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
"is_current" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_current_
, String
"is_password_pending" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_password_pending_
, String
"is_unconfirmed" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_unconfirmed_
, String
"can_accept_secret_chats" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_accept_secret_chats_
, String
"can_accept_calls" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_accept_calls_
, String
"_type" String -> Maybe SessionType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe SessionType
_type_
, String
"api_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
api_id_
, String
"application_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
application_name_
, String
"application_version" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
application_version_
, String
"is_official_application" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_official_application_
, String
"device_model" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
device_model_
, String
"platform" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
platform_
, String
"system_version" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
system_version_
, String
"log_in_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
log_in_date_
, String
"last_active_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
last_active_date_
, String
"ip_address" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
ip_address_
, String
"location" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
location_
]
instance AT.FromJSON Session where
parseJSON :: Value -> Parser Session
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
"session" -> Value -> Parser Session
parseSession Value
v
String
_ -> Parser Session
forall a. Monoid a => a
mempty
where
parseSession :: A.Value -> AT.Parser Session
parseSession :: Value -> Parser Session
parseSession = String -> (Object -> Parser Session) -> Value -> Parser Session
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Session" ((Object -> Parser Session) -> Value -> Parser Session)
-> (Object -> Parser Session) -> Value -> Parser Session
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 Bool
is_current_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_current"
Maybe Bool
is_password_pending_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_password_pending"
Maybe Bool
is_unconfirmed_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_unconfirmed"
Maybe Bool
can_accept_secret_chats_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_accept_secret_chats"
Maybe Bool
can_accept_calls_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_accept_calls"
Maybe SessionType
_type_ <- Object
o Object -> Key -> Parser (Maybe SessionType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
Maybe Int
api_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"api_id"
Maybe Text
application_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"application_name"
Maybe Text
application_version_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"application_version"
Maybe Bool
is_official_application_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_official_application"
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
platform_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"platform"
Maybe Text
system_version_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"system_version"
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 Int
last_active_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"last_active_date"
Maybe Text
ip_address_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"ip_address"
Maybe Text
location_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"location"
Session -> Parser Session
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Session -> Parser Session) -> Session -> Parser Session
forall a b. (a -> b) -> a -> b
$ Session
{ _id :: Maybe Int
_id = Maybe Int
_id_
, is_current :: Maybe Bool
is_current = Maybe Bool
is_current_
, is_password_pending :: Maybe Bool
is_password_pending = Maybe Bool
is_password_pending_
, is_unconfirmed :: Maybe Bool
is_unconfirmed = Maybe Bool
is_unconfirmed_
, can_accept_secret_chats :: Maybe Bool
can_accept_secret_chats = Maybe Bool
can_accept_secret_chats_
, can_accept_calls :: Maybe Bool
can_accept_calls = Maybe Bool
can_accept_calls_
, _type :: Maybe SessionType
_type = Maybe SessionType
_type_
, api_id :: Maybe Int
api_id = Maybe Int
api_id_
, application_name :: Maybe Text
application_name = Maybe Text
application_name_
, application_version :: Maybe Text
application_version = Maybe Text
application_version_
, is_official_application :: Maybe Bool
is_official_application = Maybe Bool
is_official_application_
, device_model :: Maybe Text
device_model = Maybe Text
device_model_
, platform :: Maybe Text
platform = Maybe Text
platform_
, system_version :: Maybe Text
system_version = Maybe Text
system_version_
, log_in_date :: Maybe Int
log_in_date = Maybe Int
log_in_date_
, last_active_date :: Maybe Int
last_active_date = Maybe Int
last_active_date_
, ip_address :: Maybe Text
ip_address = Maybe Text
ip_address_
, location :: Maybe Text
location = Maybe Text
location_
}
parseJSON Value
_ = Parser Session
forall a. Monoid a => a
mempty