module TD.Data.InlineQueryResultsButtonType
  (InlineQueryResultsButtonType(..)) 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

-- | Represents type of button in results of inline query
data InlineQueryResultsButtonType
  = InlineQueryResultsButtonTypeStartBot -- ^ Describes the button that opens a private chat with the bot and sends a start message to the bot with the given parameter
    { InlineQueryResultsButtonType -> Maybe Text
parameter :: Maybe T.Text -- ^ The parameter for the bot start message
    }
  | InlineQueryResultsButtonTypeWebApp -- ^ Describes the button that opens a Web App by calling getWebAppUrl
    { InlineQueryResultsButtonType -> Maybe Text
url :: Maybe T.Text -- ^ An HTTP URL to pass to getWebAppUrl
    }
  deriving (InlineQueryResultsButtonType
-> InlineQueryResultsButtonType -> Bool
(InlineQueryResultsButtonType
 -> InlineQueryResultsButtonType -> Bool)
-> (InlineQueryResultsButtonType
    -> InlineQueryResultsButtonType -> Bool)
-> Eq InlineQueryResultsButtonType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InlineQueryResultsButtonType
-> InlineQueryResultsButtonType -> Bool
== :: InlineQueryResultsButtonType
-> InlineQueryResultsButtonType -> Bool
$c/= :: InlineQueryResultsButtonType
-> InlineQueryResultsButtonType -> Bool
/= :: InlineQueryResultsButtonType
-> InlineQueryResultsButtonType -> Bool
Eq, Int -> InlineQueryResultsButtonType -> ShowS
[InlineQueryResultsButtonType] -> ShowS
InlineQueryResultsButtonType -> String
(Int -> InlineQueryResultsButtonType -> ShowS)
-> (InlineQueryResultsButtonType -> String)
-> ([InlineQueryResultsButtonType] -> ShowS)
-> Show InlineQueryResultsButtonType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InlineQueryResultsButtonType -> ShowS
showsPrec :: Int -> InlineQueryResultsButtonType -> ShowS
$cshow :: InlineQueryResultsButtonType -> String
show :: InlineQueryResultsButtonType -> String
$cshowList :: [InlineQueryResultsButtonType] -> ShowS
showList :: [InlineQueryResultsButtonType] -> ShowS
Show)

instance I.ShortShow InlineQueryResultsButtonType where
  shortShow :: InlineQueryResultsButtonType -> String
shortShow InlineQueryResultsButtonTypeStartBot
    { parameter :: InlineQueryResultsButtonType -> Maybe Text
parameter = Maybe Text
parameter_
    }
      = String
"InlineQueryResultsButtonTypeStartBot"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"parameter" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
parameter_
        ]
  shortShow InlineQueryResultsButtonTypeWebApp
    { url :: InlineQueryResultsButtonType -> Maybe Text
url = Maybe Text
url_
    }
      = String
"InlineQueryResultsButtonTypeWebApp"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
        ]

instance AT.FromJSON InlineQueryResultsButtonType where
  parseJSON :: Value -> Parser InlineQueryResultsButtonType
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
"inlineQueryResultsButtonTypeStartBot" -> Value -> Parser InlineQueryResultsButtonType
parseInlineQueryResultsButtonTypeStartBot Value
v
      String
"inlineQueryResultsButtonTypeWebApp"   -> Value -> Parser InlineQueryResultsButtonType
parseInlineQueryResultsButtonTypeWebApp Value
v
      String
_                                      -> Parser InlineQueryResultsButtonType
forall a. Monoid a => a
mempty
    
    where
      parseInlineQueryResultsButtonTypeStartBot :: A.Value -> AT.Parser InlineQueryResultsButtonType
      parseInlineQueryResultsButtonTypeStartBot :: Value -> Parser InlineQueryResultsButtonType
parseInlineQueryResultsButtonTypeStartBot = String
-> (Object -> Parser InlineQueryResultsButtonType)
-> Value
-> Parser InlineQueryResultsButtonType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InlineQueryResultsButtonTypeStartBot" ((Object -> Parser InlineQueryResultsButtonType)
 -> Value -> Parser InlineQueryResultsButtonType)
-> (Object -> Parser InlineQueryResultsButtonType)
-> Value
-> Parser InlineQueryResultsButtonType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
parameter_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"parameter"
        InlineQueryResultsButtonType -> Parser InlineQueryResultsButtonType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InlineQueryResultsButtonType
 -> Parser InlineQueryResultsButtonType)
-> InlineQueryResultsButtonType
-> Parser InlineQueryResultsButtonType
forall a b. (a -> b) -> a -> b
$ InlineQueryResultsButtonTypeStartBot
          { parameter :: Maybe Text
parameter = Maybe Text
parameter_
          }
      parseInlineQueryResultsButtonTypeWebApp :: A.Value -> AT.Parser InlineQueryResultsButtonType
      parseInlineQueryResultsButtonTypeWebApp :: Value -> Parser InlineQueryResultsButtonType
parseInlineQueryResultsButtonTypeWebApp = String
-> (Object -> Parser InlineQueryResultsButtonType)
-> Value
-> Parser InlineQueryResultsButtonType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InlineQueryResultsButtonTypeWebApp" ((Object -> Parser InlineQueryResultsButtonType)
 -> Value -> Parser InlineQueryResultsButtonType)
-> (Object -> Parser InlineQueryResultsButtonType)
-> Value
-> Parser InlineQueryResultsButtonType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"url"
        InlineQueryResultsButtonType -> Parser InlineQueryResultsButtonType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InlineQueryResultsButtonType
 -> Parser InlineQueryResultsButtonType)
-> InlineQueryResultsButtonType
-> Parser InlineQueryResultsButtonType
forall a b. (a -> b) -> a -> b
$ InlineQueryResultsButtonTypeWebApp
          { url :: Maybe Text
url = Maybe Text
url_
          }
  parseJSON Value
_ = Parser InlineQueryResultsButtonType
forall a. Monoid a => a
mempty

instance AT.ToJSON InlineQueryResultsButtonType where
  toJSON :: InlineQueryResultsButtonType -> Value
toJSON InlineQueryResultsButtonTypeStartBot
    { parameter :: InlineQueryResultsButtonType -> Maybe Text
parameter = Maybe Text
parameter_
    }
      = [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
"inlineQueryResultsButtonTypeStartBot"
        , Key
"parameter" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
parameter_
        ]
  toJSON InlineQueryResultsButtonTypeWebApp
    { url :: InlineQueryResultsButtonType -> Maybe Text
url = Maybe Text
url_
    }
      = [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
"inlineQueryResultsButtonTypeWebApp"
        , Key
"url"   Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
url_
        ]