module TD.Data.BusinessConnectedBotInfo
  (BusinessConnectedBotInfo(..)) 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.BusinessConnectedBot as BusinessConnectedBot
import qualified Data.Text as T

data BusinessConnectedBotInfo
  = BusinessConnectedBotInfo -- ^ Describes a connection of a bot to an account
    { BusinessConnectedBotInfo -> Maybe BusinessConnectedBot
bot             :: Maybe BusinessConnectedBot.BusinessConnectedBot -- ^ Information about the bot
    , BusinessConnectedBotInfo -> Maybe Int
connection_date :: Maybe Int                                       -- ^ Point in time (Unix timestamp) when the bot was added; may be 0 if unknown
    , BusinessConnectedBotInfo -> Maybe Text
device_model    :: Maybe T.Text                                    -- ^ Model of the device that was used for the bot connection, as provided by the application; may be empty if unknown
    , BusinessConnectedBotInfo -> Maybe Text
location        :: Maybe T.Text                                    -- ^ A human-readable description of the location from which the bot was connected, based on the IP address; may be empty if unknown
    }
  deriving (BusinessConnectedBotInfo -> BusinessConnectedBotInfo -> Bool
(BusinessConnectedBotInfo -> BusinessConnectedBotInfo -> Bool)
-> (BusinessConnectedBotInfo -> BusinessConnectedBotInfo -> Bool)
-> Eq BusinessConnectedBotInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BusinessConnectedBotInfo -> BusinessConnectedBotInfo -> Bool
== :: BusinessConnectedBotInfo -> BusinessConnectedBotInfo -> Bool
$c/= :: BusinessConnectedBotInfo -> BusinessConnectedBotInfo -> Bool
/= :: BusinessConnectedBotInfo -> BusinessConnectedBotInfo -> Bool
Eq, Int -> BusinessConnectedBotInfo -> ShowS
[BusinessConnectedBotInfo] -> ShowS
BusinessConnectedBotInfo -> String
(Int -> BusinessConnectedBotInfo -> ShowS)
-> (BusinessConnectedBotInfo -> String)
-> ([BusinessConnectedBotInfo] -> ShowS)
-> Show BusinessConnectedBotInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BusinessConnectedBotInfo -> ShowS
showsPrec :: Int -> BusinessConnectedBotInfo -> ShowS
$cshow :: BusinessConnectedBotInfo -> String
show :: BusinessConnectedBotInfo -> String
$cshowList :: [BusinessConnectedBotInfo] -> ShowS
showList :: [BusinessConnectedBotInfo] -> ShowS
Show)

instance I.ShortShow BusinessConnectedBotInfo where
  shortShow :: BusinessConnectedBotInfo -> String
shortShow BusinessConnectedBotInfo
    { bot :: BusinessConnectedBotInfo -> Maybe BusinessConnectedBot
bot             = Maybe BusinessConnectedBot
bot_
    , connection_date :: BusinessConnectedBotInfo -> Maybe Int
connection_date = Maybe Int
connection_date_
    , device_model :: BusinessConnectedBotInfo -> Maybe Text
device_model    = Maybe Text
device_model_
    , location :: BusinessConnectedBotInfo -> Maybe Text
location        = Maybe Text
location_
    }
      = String
"BusinessConnectedBotInfo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"bot"             String -> Maybe BusinessConnectedBot -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe BusinessConnectedBot
bot_
        , String
"connection_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
connection_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 BusinessConnectedBotInfo where
  parseJSON :: Value -> Parser BusinessConnectedBotInfo
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
"businessConnectedBotInfo" -> Value -> Parser BusinessConnectedBotInfo
parseBusinessConnectedBotInfo Value
v
      String
_                          -> Parser BusinessConnectedBotInfo
forall a. Monoid a => a
mempty
    
    where
      parseBusinessConnectedBotInfo :: A.Value -> AT.Parser BusinessConnectedBotInfo
      parseBusinessConnectedBotInfo :: Value -> Parser BusinessConnectedBotInfo
parseBusinessConnectedBotInfo = String
-> (Object -> Parser BusinessConnectedBotInfo)
-> Value
-> Parser BusinessConnectedBotInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BusinessConnectedBotInfo" ((Object -> Parser BusinessConnectedBotInfo)
 -> Value -> Parser BusinessConnectedBotInfo)
-> (Object -> Parser BusinessConnectedBotInfo)
-> Value
-> Parser BusinessConnectedBotInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe BusinessConnectedBot
bot_             <- Object
o Object -> Key -> Parser (Maybe BusinessConnectedBot)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"bot"
        Maybe Int
connection_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"connection_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"
        BusinessConnectedBotInfo -> Parser BusinessConnectedBotInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BusinessConnectedBotInfo -> Parser BusinessConnectedBotInfo)
-> BusinessConnectedBotInfo -> Parser BusinessConnectedBotInfo
forall a b. (a -> b) -> a -> b
$ BusinessConnectedBotInfo
          { bot :: Maybe BusinessConnectedBot
bot             = Maybe BusinessConnectedBot
bot_
          , connection_date :: Maybe Int
connection_date = Maybe Int
connection_date_
          , device_model :: Maybe Text
device_model    = Maybe Text
device_model_
          , location :: Maybe Text
location        = Maybe Text
location_
          }
  parseJSON Value
_ = Parser BusinessConnectedBotInfo
forall a. Monoid a => a
mempty