module TD.Data.ChatBoostLink
  (ChatBoostLink(..)) 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 ChatBoostLink
  = ChatBoostLink -- ^ Contains an HTTPS link to boost a chat
    { ChatBoostLink -> Maybe Text
link      :: Maybe T.Text -- ^ The link
    , ChatBoostLink -> Maybe Bool
is_public :: Maybe Bool   -- ^ True, if the link will work for non-members of the chat
    }
  deriving (ChatBoostLink -> ChatBoostLink -> Bool
(ChatBoostLink -> ChatBoostLink -> Bool)
-> (ChatBoostLink -> ChatBoostLink -> Bool) -> Eq ChatBoostLink
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatBoostLink -> ChatBoostLink -> Bool
== :: ChatBoostLink -> ChatBoostLink -> Bool
$c/= :: ChatBoostLink -> ChatBoostLink -> Bool
/= :: ChatBoostLink -> ChatBoostLink -> Bool
Eq, Int -> ChatBoostLink -> ShowS
[ChatBoostLink] -> ShowS
ChatBoostLink -> String
(Int -> ChatBoostLink -> ShowS)
-> (ChatBoostLink -> String)
-> ([ChatBoostLink] -> ShowS)
-> Show ChatBoostLink
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatBoostLink -> ShowS
showsPrec :: Int -> ChatBoostLink -> ShowS
$cshow :: ChatBoostLink -> String
show :: ChatBoostLink -> String
$cshowList :: [ChatBoostLink] -> ShowS
showList :: [ChatBoostLink] -> ShowS
Show)

instance I.ShortShow ChatBoostLink where
  shortShow :: ChatBoostLink -> String
shortShow ChatBoostLink
    { link :: ChatBoostLink -> Maybe Text
link      = Maybe Text
link_
    , is_public :: ChatBoostLink -> Maybe Bool
is_public = Maybe Bool
is_public_
    }
      = String
"ChatBoostLink"
        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
"is_public" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_public_
        ]

instance AT.FromJSON ChatBoostLink where
  parseJSON :: Value -> Parser ChatBoostLink
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
"chatBoostLink" -> Value -> Parser ChatBoostLink
parseChatBoostLink Value
v
      String
_               -> Parser ChatBoostLink
forall a. Monoid a => a
mempty
    
    where
      parseChatBoostLink :: A.Value -> AT.Parser ChatBoostLink
      parseChatBoostLink :: Value -> Parser ChatBoostLink
parseChatBoostLink = String
-> (Object -> Parser ChatBoostLink)
-> Value
-> Parser ChatBoostLink
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatBoostLink" ((Object -> Parser ChatBoostLink) -> Value -> Parser ChatBoostLink)
-> (Object -> Parser ChatBoostLink)
-> Value
-> Parser ChatBoostLink
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 Bool
is_public_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_public"
        ChatBoostLink -> Parser ChatBoostLink
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatBoostLink -> Parser ChatBoostLink)
-> ChatBoostLink -> Parser ChatBoostLink
forall a b. (a -> b) -> a -> b
$ ChatBoostLink
          { link :: Maybe Text
link      = Maybe Text
link_
          , is_public :: Maybe Bool
is_public = Maybe Bool
is_public_
          }
  parseJSON Value
_ = Parser ChatBoostLink
forall a. Monoid a => a
mempty