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

data BusinessChatLink
  = BusinessChatLink -- ^ Contains information about a business chat link
    { BusinessChatLink -> Maybe Text
link       :: Maybe T.Text                      -- ^ The HTTPS link
    , BusinessChatLink -> Maybe FormattedText
text       :: Maybe FormattedText.FormattedText -- ^ Message draft text that will be added to the input field
    , BusinessChatLink -> Maybe Text
title      :: Maybe T.Text                      -- ^ Link title
    , BusinessChatLink -> Maybe Int
view_count :: Maybe Int                         -- ^ Number of times the link was used
    }
  deriving (BusinessChatLink -> BusinessChatLink -> Bool
(BusinessChatLink -> BusinessChatLink -> Bool)
-> (BusinessChatLink -> BusinessChatLink -> Bool)
-> Eq BusinessChatLink
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BusinessChatLink -> BusinessChatLink -> Bool
== :: BusinessChatLink -> BusinessChatLink -> Bool
$c/= :: BusinessChatLink -> BusinessChatLink -> Bool
/= :: BusinessChatLink -> BusinessChatLink -> Bool
Eq, Int -> BusinessChatLink -> ShowS
[BusinessChatLink] -> ShowS
BusinessChatLink -> String
(Int -> BusinessChatLink -> ShowS)
-> (BusinessChatLink -> String)
-> ([BusinessChatLink] -> ShowS)
-> Show BusinessChatLink
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BusinessChatLink -> ShowS
showsPrec :: Int -> BusinessChatLink -> ShowS
$cshow :: BusinessChatLink -> String
show :: BusinessChatLink -> String
$cshowList :: [BusinessChatLink] -> ShowS
showList :: [BusinessChatLink] -> ShowS
Show)

instance I.ShortShow BusinessChatLink where
  shortShow :: BusinessChatLink -> String
shortShow BusinessChatLink
    { link :: BusinessChatLink -> Maybe Text
link       = Maybe Text
link_
    , text :: BusinessChatLink -> Maybe FormattedText
text       = Maybe FormattedText
text_
    , title :: BusinessChatLink -> Maybe Text
title      = Maybe Text
title_
    , view_count :: BusinessChatLink -> Maybe Int
view_count = Maybe Int
view_count_
    }
      = String
"BusinessChatLink"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"link"       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
link_
        , String
"text"       String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
text_
        , String
"title"      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"view_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
view_count_
        ]

instance AT.FromJSON BusinessChatLink where
  parseJSON :: Value -> Parser BusinessChatLink
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
"businessChatLink" -> Value -> Parser BusinessChatLink
parseBusinessChatLink Value
v
      String
_                  -> Parser BusinessChatLink
forall a. Monoid a => a
mempty
    
    where
      parseBusinessChatLink :: A.Value -> AT.Parser BusinessChatLink
      parseBusinessChatLink :: Value -> Parser BusinessChatLink
parseBusinessChatLink = String
-> (Object -> Parser BusinessChatLink)
-> Value
-> Parser BusinessChatLink
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BusinessChatLink" ((Object -> Parser BusinessChatLink)
 -> Value -> Parser BusinessChatLink)
-> (Object -> Parser BusinessChatLink)
-> Value
-> Parser BusinessChatLink
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
link_       <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"link"
        Maybe FormattedText
text_       <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe Text
title_      <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        Maybe Int
view_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"view_count"
        BusinessChatLink -> Parser BusinessChatLink
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BusinessChatLink -> Parser BusinessChatLink)
-> BusinessChatLink -> Parser BusinessChatLink
forall a b. (a -> b) -> a -> b
$ BusinessChatLink
          { link :: Maybe Text
link       = Maybe Text
link_
          , text :: Maybe FormattedText
text       = Maybe FormattedText
text_
          , title :: Maybe Text
title      = Maybe Text
title_
          , view_count :: Maybe Int
view_count = Maybe Int
view_count_
          }
  parseJSON Value
_ = Parser BusinessChatLink
forall a. Monoid a => a
mempty