module TD.Data.BusinessChatLinkInfo
  (BusinessChatLinkInfo(..)) 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.FormattedText as FormattedText

data BusinessChatLinkInfo
  = BusinessChatLinkInfo -- ^ Contains information about a business chat link
    { BusinessChatLinkInfo -> Maybe Int
chat_id :: Maybe Int                         -- ^ Identifier of the private chat that created the link
    , BusinessChatLinkInfo -> Maybe FormattedText
text    :: Maybe FormattedText.FormattedText -- ^ Message draft text that must be added to the input field
    }
  deriving (BusinessChatLinkInfo -> BusinessChatLinkInfo -> Bool
(BusinessChatLinkInfo -> BusinessChatLinkInfo -> Bool)
-> (BusinessChatLinkInfo -> BusinessChatLinkInfo -> Bool)
-> Eq BusinessChatLinkInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BusinessChatLinkInfo -> BusinessChatLinkInfo -> Bool
== :: BusinessChatLinkInfo -> BusinessChatLinkInfo -> Bool
$c/= :: BusinessChatLinkInfo -> BusinessChatLinkInfo -> Bool
/= :: BusinessChatLinkInfo -> BusinessChatLinkInfo -> Bool
Eq, Int -> BusinessChatLinkInfo -> ShowS
[BusinessChatLinkInfo] -> ShowS
BusinessChatLinkInfo -> String
(Int -> BusinessChatLinkInfo -> ShowS)
-> (BusinessChatLinkInfo -> String)
-> ([BusinessChatLinkInfo] -> ShowS)
-> Show BusinessChatLinkInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BusinessChatLinkInfo -> ShowS
showsPrec :: Int -> BusinessChatLinkInfo -> ShowS
$cshow :: BusinessChatLinkInfo -> String
show :: BusinessChatLinkInfo -> String
$cshowList :: [BusinessChatLinkInfo] -> ShowS
showList :: [BusinessChatLinkInfo] -> ShowS
Show)

instance I.ShortShow BusinessChatLinkInfo where
  shortShow :: BusinessChatLinkInfo -> String
shortShow BusinessChatLinkInfo
    { chat_id :: BusinessChatLinkInfo -> Maybe Int
chat_id = Maybe Int
chat_id_
    , text :: BusinessChatLinkInfo -> Maybe FormattedText
text    = Maybe FormattedText
text_
    }
      = String
"BusinessChatLinkInfo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
        , String
"text"    String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
text_
        ]

instance AT.FromJSON BusinessChatLinkInfo where
  parseJSON :: Value -> Parser BusinessChatLinkInfo
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
"businessChatLinkInfo" -> Value -> Parser BusinessChatLinkInfo
parseBusinessChatLinkInfo Value
v
      String
_                      -> Parser BusinessChatLinkInfo
forall a. Monoid a => a
mempty
    
    where
      parseBusinessChatLinkInfo :: A.Value -> AT.Parser BusinessChatLinkInfo
      parseBusinessChatLinkInfo :: Value -> Parser BusinessChatLinkInfo
parseBusinessChatLinkInfo = String
-> (Object -> Parser BusinessChatLinkInfo)
-> Value
-> Parser BusinessChatLinkInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BusinessChatLinkInfo" ((Object -> Parser BusinessChatLinkInfo)
 -> Value -> Parser BusinessChatLinkInfo)
-> (Object -> Parser BusinessChatLinkInfo)
-> Value
-> Parser BusinessChatLinkInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chat_id"
        Maybe FormattedText
text_    <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        BusinessChatLinkInfo -> Parser BusinessChatLinkInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BusinessChatLinkInfo -> Parser BusinessChatLinkInfo)
-> BusinessChatLinkInfo -> Parser BusinessChatLinkInfo
forall a b. (a -> b) -> a -> b
$ BusinessChatLinkInfo
          { chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
          , text :: Maybe FormattedText
text    = Maybe FormattedText
text_
          }
  parseJSON Value
_ = Parser BusinessChatLinkInfo
forall a. Monoid a => a
mempty