module TD.Data.BusinessConnectedBot
  ( BusinessConnectedBot(..)    
  , defaultBusinessConnectedBot 
  ) 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.BusinessRecipients as BusinessRecipients

data BusinessConnectedBot
  = BusinessConnectedBot -- ^ Describes a bot connected to a business account
    { BusinessConnectedBot -> Maybe Int
bot_user_id :: Maybe Int                                   -- ^ User identifier of the bot
    , BusinessConnectedBot -> Maybe BusinessRecipients
recipients  :: Maybe BusinessRecipients.BusinessRecipients -- ^ Private chats that will be accessible to the bot
    , BusinessConnectedBot -> Maybe Bool
can_reply   :: Maybe Bool                                  -- ^ True, if the bot can send messages to the private chats; false otherwise
    }
  deriving (BusinessConnectedBot -> BusinessConnectedBot -> Bool
(BusinessConnectedBot -> BusinessConnectedBot -> Bool)
-> (BusinessConnectedBot -> BusinessConnectedBot -> Bool)
-> Eq BusinessConnectedBot
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BusinessConnectedBot -> BusinessConnectedBot -> Bool
== :: BusinessConnectedBot -> BusinessConnectedBot -> Bool
$c/= :: BusinessConnectedBot -> BusinessConnectedBot -> Bool
/= :: BusinessConnectedBot -> BusinessConnectedBot -> Bool
Eq, Int -> BusinessConnectedBot -> ShowS
[BusinessConnectedBot] -> ShowS
BusinessConnectedBot -> String
(Int -> BusinessConnectedBot -> ShowS)
-> (BusinessConnectedBot -> String)
-> ([BusinessConnectedBot] -> ShowS)
-> Show BusinessConnectedBot
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BusinessConnectedBot -> ShowS
showsPrec :: Int -> BusinessConnectedBot -> ShowS
$cshow :: BusinessConnectedBot -> String
show :: BusinessConnectedBot -> String
$cshowList :: [BusinessConnectedBot] -> ShowS
showList :: [BusinessConnectedBot] -> ShowS
Show)

instance I.ShortShow BusinessConnectedBot where
  shortShow :: BusinessConnectedBot -> String
shortShow BusinessConnectedBot
    { bot_user_id :: BusinessConnectedBot -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
    , recipients :: BusinessConnectedBot -> Maybe BusinessRecipients
recipients  = Maybe BusinessRecipients
recipients_
    , can_reply :: BusinessConnectedBot -> Maybe Bool
can_reply   = Maybe Bool
can_reply_
    }
      = String
"BusinessConnectedBot"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"bot_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bot_user_id_
        , String
"recipients"  String -> Maybe BusinessRecipients -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe BusinessRecipients
recipients_
        , String
"can_reply"   String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_reply_
        ]

instance AT.FromJSON BusinessConnectedBot where
  parseJSON :: Value -> Parser BusinessConnectedBot
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
"businessConnectedBot" -> Value -> Parser BusinessConnectedBot
parseBusinessConnectedBot Value
v
      String
_                      -> Parser BusinessConnectedBot
forall a. Monoid a => a
mempty
    
    where
      parseBusinessConnectedBot :: A.Value -> AT.Parser BusinessConnectedBot
      parseBusinessConnectedBot :: Value -> Parser BusinessConnectedBot
parseBusinessConnectedBot = String
-> (Object -> Parser BusinessConnectedBot)
-> Value
-> Parser BusinessConnectedBot
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BusinessConnectedBot" ((Object -> Parser BusinessConnectedBot)
 -> Value -> Parser BusinessConnectedBot)
-> (Object -> Parser BusinessConnectedBot)
-> Value
-> Parser BusinessConnectedBot
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        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 BusinessRecipients
recipients_  <- Object
o Object -> Key -> Parser (Maybe BusinessRecipients)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"recipients"
        Maybe Bool
can_reply_   <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_reply"
        BusinessConnectedBot -> Parser BusinessConnectedBot
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BusinessConnectedBot -> Parser BusinessConnectedBot)
-> BusinessConnectedBot -> Parser BusinessConnectedBot
forall a b. (a -> b) -> a -> b
$ BusinessConnectedBot
          { bot_user_id :: Maybe Int
bot_user_id = Maybe Int
bot_user_id_
          , recipients :: Maybe BusinessRecipients
recipients  = Maybe BusinessRecipients
recipients_
          , can_reply :: Maybe Bool
can_reply   = Maybe Bool
can_reply_
          }
  parseJSON Value
_ = Parser BusinessConnectedBot
forall a. Monoid a => a
mempty

instance AT.ToJSON BusinessConnectedBot where
  toJSON :: BusinessConnectedBot -> Value
toJSON BusinessConnectedBot
    { bot_user_id :: BusinessConnectedBot -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
    , recipients :: BusinessConnectedBot -> Maybe BusinessRecipients
recipients  = Maybe BusinessRecipients
recipients_
    , can_reply :: BusinessConnectedBot -> Maybe Bool
can_reply   = Maybe Bool
can_reply_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"       Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"businessConnectedBot"
        , Key
"bot_user_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
bot_user_id_
        , Key
"recipients"  Key -> Maybe BusinessRecipients -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe BusinessRecipients
recipients_
        , Key
"can_reply"   Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
can_reply_
        ]

defaultBusinessConnectedBot :: BusinessConnectedBot
defaultBusinessConnectedBot :: BusinessConnectedBot
defaultBusinessConnectedBot =
  BusinessConnectedBot
    { bot_user_id :: Maybe Int
bot_user_id = Maybe Int
forall a. Maybe a
Nothing
    , recipients :: Maybe BusinessRecipients
recipients  = Maybe BusinessRecipients
forall a. Maybe a
Nothing
    , can_reply :: Maybe Bool
can_reply   = Maybe Bool
forall a. Maybe a
Nothing
    }