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 TD.Data.SessionType as SessionType
import qualified Data.Text as T

data UnconfirmedSession
  = UnconfirmedSession -- ^ Contains information about an unconfirmed session
    { UnconfirmedSession -> Maybe SessionType
_type        :: Maybe SessionType.SessionType -- ^ Session type
    , UnconfirmedSession -> Maybe Int
date         :: Maybe Int                     -- ^ Point in time (Unix timestamp) when the user has logged in or the business bot was connected
    , UnconfirmedSession -> Maybe Text
device_model :: Maybe T.Text                  -- ^ Model of the device that was used for the session creation, as provided by the application
    , UnconfirmedSession -> Maybe Text
location     :: Maybe T.Text                  -- ^ A human-readable description of the location from which the session was created, based on the IP address
    }
  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
    { _type :: UnconfirmedSession -> Maybe SessionType
_type        = Maybe SessionType
_type_
    , date :: UnconfirmedSession -> Maybe Int
date         = Maybe Int
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
"_type"        String -> Maybe SessionType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe SessionType
_type_
        , String
"date"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
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 SessionType
_type_        <- Object
o Object -> Key -> Parser (Maybe SessionType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"type"
        Maybe Int
date_         <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"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
          { _type :: Maybe SessionType
_type        = Maybe SessionType
_type_
          , date :: Maybe Int
date         = Maybe Int
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