module TD.Data.ConnectedWebsite
  (ConnectedWebsite(..)) 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 ConnectedWebsite
  = ConnectedWebsite -- ^ Contains information about one website the current user is logged in with Telegram
    { ConnectedWebsite -> Maybe Int
_id              :: Maybe Int    -- ^ Website identifier
    , ConnectedWebsite -> Maybe Text
domain_name      :: Maybe T.Text -- ^ The domain name of the website
    , ConnectedWebsite -> Maybe Int
bot_user_id      :: Maybe Int    -- ^ User identifier of a bot linked with the website
    , ConnectedWebsite -> Maybe Text
browser          :: Maybe T.Text -- ^ The version of a browser used to log in
    , ConnectedWebsite -> Maybe Text
platform         :: Maybe T.Text -- ^ Operating system the browser is running on
    , ConnectedWebsite -> Maybe Int
log_in_date      :: Maybe Int    -- ^ Point in time (Unix timestamp) when the user was logged in
    , ConnectedWebsite -> Maybe Int
last_active_date :: Maybe Int    -- ^ Point in time (Unix timestamp) when obtained authorization was last used
    , ConnectedWebsite -> Maybe Text
ip_address       :: Maybe T.Text -- ^ IP address from which the user was logged in, in human-readable format
    , ConnectedWebsite -> Maybe Text
location         :: Maybe T.Text -- ^ Human-readable description of a country and a region from which the user was logged in, based on the IP address
    }
  deriving (ConnectedWebsite -> ConnectedWebsite -> Bool
(ConnectedWebsite -> ConnectedWebsite -> Bool)
-> (ConnectedWebsite -> ConnectedWebsite -> Bool)
-> Eq ConnectedWebsite
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConnectedWebsite -> ConnectedWebsite -> Bool
== :: ConnectedWebsite -> ConnectedWebsite -> Bool
$c/= :: ConnectedWebsite -> ConnectedWebsite -> Bool
/= :: ConnectedWebsite -> ConnectedWebsite -> Bool
Eq, Int -> ConnectedWebsite -> ShowS
[ConnectedWebsite] -> ShowS
ConnectedWebsite -> String
(Int -> ConnectedWebsite -> ShowS)
-> (ConnectedWebsite -> String)
-> ([ConnectedWebsite] -> ShowS)
-> Show ConnectedWebsite
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConnectedWebsite -> ShowS
showsPrec :: Int -> ConnectedWebsite -> ShowS
$cshow :: ConnectedWebsite -> String
show :: ConnectedWebsite -> String
$cshowList :: [ConnectedWebsite] -> ShowS
showList :: [ConnectedWebsite] -> ShowS
Show)

instance I.ShortShow ConnectedWebsite where
  shortShow :: ConnectedWebsite -> String
shortShow ConnectedWebsite
    { _id :: ConnectedWebsite -> Maybe Int
_id              = Maybe Int
_id_
    , domain_name :: ConnectedWebsite -> Maybe Text
domain_name      = Maybe Text
domain_name_
    , bot_user_id :: ConnectedWebsite -> Maybe Int
bot_user_id      = Maybe Int
bot_user_id_
    , browser :: ConnectedWebsite -> Maybe Text
browser          = Maybe Text
browser_
    , platform :: ConnectedWebsite -> Maybe Text
platform         = Maybe Text
platform_
    , log_in_date :: ConnectedWebsite -> Maybe Int
log_in_date      = Maybe Int
log_in_date_
    , last_active_date :: ConnectedWebsite -> Maybe Int
last_active_date = Maybe Int
last_active_date_
    , ip_address :: ConnectedWebsite -> Maybe Text
ip_address       = Maybe Text
ip_address_
    , location :: ConnectedWebsite -> Maybe Text
location         = Maybe Text
location_
    }
      = String
"ConnectedWebsite"
        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
"domain_name"      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
domain_name_
        , String
"bot_user_id"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bot_user_id_
        , String
"browser"          String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
browser_
        , String
"platform"         String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
platform_
        , 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 ConnectedWebsite where
  parseJSON :: Value -> Parser ConnectedWebsite
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
"connectedWebsite" -> Value -> Parser ConnectedWebsite
parseConnectedWebsite Value
v
      String
_                  -> Parser ConnectedWebsite
forall a. Monoid a => a
mempty
    
    where
      parseConnectedWebsite :: A.Value -> AT.Parser ConnectedWebsite
      parseConnectedWebsite :: Value -> Parser ConnectedWebsite
parseConnectedWebsite = String
-> (Object -> Parser ConnectedWebsite)
-> Value
-> Parser ConnectedWebsite
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ConnectedWebsite" ((Object -> Parser ConnectedWebsite)
 -> Value -> Parser ConnectedWebsite)
-> (Object -> Parser ConnectedWebsite)
-> Value
-> Parser ConnectedWebsite
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 Text
domain_name_      <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"domain_name"
        Maybe Int
bot_user_id_      <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"bot_user_id"
        Maybe Text
browser_          <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"browser"
        Maybe Text
platform_         <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"platform"
        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"
        ConnectedWebsite -> Parser ConnectedWebsite
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ConnectedWebsite -> Parser ConnectedWebsite)
-> ConnectedWebsite -> Parser ConnectedWebsite
forall a b. (a -> b) -> a -> b
$ ConnectedWebsite
          { _id :: Maybe Int
_id              = Maybe Int
_id_
          , domain_name :: Maybe Text
domain_name      = Maybe Text
domain_name_
          , bot_user_id :: Maybe Int
bot_user_id      = Maybe Int
bot_user_id_
          , browser :: Maybe Text
browser          = Maybe Text
browser_
          , platform :: Maybe Text
platform         = Maybe Text
platform_
          , 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 ConnectedWebsite
forall a. Monoid a => a
mempty