module TD.Query.OpenWebApp
  (OpenWebApp(..)
  , defaultOpenWebApp
  ) 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.ThemeParameters as ThemeParameters
import qualified TD.Data.InputMessageReplyTo as InputMessageReplyTo

-- | Informs TDLib that a Web App is being opened from the attachment menu, a botMenuButton button, an internalLinkTypeAttachmentMenuBot link, or an inlineKeyboardButtonTypeWebApp button. For each bot, a confirmation alert about data sent to the bot must be shown once. Returns 'TD.Data.WebAppInfo.WebAppInfo'
data OpenWebApp
  = OpenWebApp
    { OpenWebApp -> Maybe Int
chat_id           :: Maybe Int                                     -- ^ Identifier of the chat in which the Web App is opened. The Web App can't be opened in secret chats
    , OpenWebApp -> Maybe Int
bot_user_id       :: Maybe Int                                     -- ^ Identifier of the bot, providing the Web App
    , OpenWebApp -> Maybe Text
url               :: Maybe T.Text                                  -- ^ The URL from an inlineKeyboardButtonTypeWebApp button, a botMenuButton button, an internalLinkTypeAttachmentMenuBot link, or an empty string otherwise
    , OpenWebApp -> Maybe ThemeParameters
theme             :: Maybe ThemeParameters.ThemeParameters         -- ^ Preferred Web App theme; pass null to use the default theme
    , OpenWebApp -> Maybe Text
application_name  :: Maybe T.Text                                  -- ^ Short name of the current application; 0-64 English letters, digits, and underscores
    , OpenWebApp -> Maybe Int
message_thread_id :: Maybe Int                                     -- ^ If not 0, the message thread identifier in which the message will be sent
    , OpenWebApp -> Maybe InputMessageReplyTo
reply_to          :: Maybe InputMessageReplyTo.InputMessageReplyTo -- ^ Information about the message or story to be replied in the message sent by the Web App; pass null if none
    }
  deriving (OpenWebApp -> OpenWebApp -> Bool
(OpenWebApp -> OpenWebApp -> Bool)
-> (OpenWebApp -> OpenWebApp -> Bool) -> Eq OpenWebApp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OpenWebApp -> OpenWebApp -> Bool
== :: OpenWebApp -> OpenWebApp -> Bool
$c/= :: OpenWebApp -> OpenWebApp -> Bool
/= :: OpenWebApp -> OpenWebApp -> Bool
Eq, Int -> OpenWebApp -> ShowS
[OpenWebApp] -> ShowS
OpenWebApp -> String
(Int -> OpenWebApp -> ShowS)
-> (OpenWebApp -> String)
-> ([OpenWebApp] -> ShowS)
-> Show OpenWebApp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OpenWebApp -> ShowS
showsPrec :: Int -> OpenWebApp -> ShowS
$cshow :: OpenWebApp -> String
show :: OpenWebApp -> String
$cshowList :: [OpenWebApp] -> ShowS
showList :: [OpenWebApp] -> ShowS
Show)

instance I.ShortShow OpenWebApp where
  shortShow :: OpenWebApp -> String
shortShow
    OpenWebApp
      { chat_id :: OpenWebApp -> Maybe Int
chat_id           = Maybe Int
chat_id_
      , bot_user_id :: OpenWebApp -> Maybe Int
bot_user_id       = Maybe Int
bot_user_id_
      , url :: OpenWebApp -> Maybe Text
url               = Maybe Text
url_
      , theme :: OpenWebApp -> Maybe ThemeParameters
theme             = Maybe ThemeParameters
theme_
      , application_name :: OpenWebApp -> Maybe Text
application_name  = Maybe Text
application_name_
      , message_thread_id :: OpenWebApp -> Maybe Int
message_thread_id = Maybe Int
message_thread_id_
      , reply_to :: OpenWebApp -> Maybe InputMessageReplyTo
reply_to          = Maybe InputMessageReplyTo
reply_to_
      }
        = String
"OpenWebApp"
          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
"bot_user_id"       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bot_user_id_
          , String
"url"               String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
          , String
"theme"             String -> Maybe ThemeParameters -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ThemeParameters
theme_
          , String
"application_name"  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
application_name_
          , String
"message_thread_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_thread_id_
          , String
"reply_to"          String -> Maybe InputMessageReplyTo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputMessageReplyTo
reply_to_
          ]

instance AT.ToJSON OpenWebApp where
  toJSON :: OpenWebApp -> Value
toJSON
    OpenWebApp
      { chat_id :: OpenWebApp -> Maybe Int
chat_id           = Maybe Int
chat_id_
      , bot_user_id :: OpenWebApp -> Maybe Int
bot_user_id       = Maybe Int
bot_user_id_
      , url :: OpenWebApp -> Maybe Text
url               = Maybe Text
url_
      , theme :: OpenWebApp -> Maybe ThemeParameters
theme             = Maybe ThemeParameters
theme_
      , application_name :: OpenWebApp -> Maybe Text
application_name  = Maybe Text
application_name_
      , message_thread_id :: OpenWebApp -> Maybe Int
message_thread_id = Maybe Int
message_thread_id_
      , reply_to :: OpenWebApp -> Maybe InputMessageReplyTo
reply_to          = Maybe InputMessageReplyTo
reply_to_
      }
        = [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
"openWebApp"
          , Key
"chat_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
chat_id_
          , 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
"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_
          , Key
"theme"             Key -> Maybe ThemeParameters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe ThemeParameters
theme_
          , Key
"application_name"  Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
application_name_
          , Key
"message_thread_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
message_thread_id_
          , Key
"reply_to"          Key -> Maybe InputMessageReplyTo -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputMessageReplyTo
reply_to_
          ]

defaultOpenWebApp :: OpenWebApp
defaultOpenWebApp :: OpenWebApp
defaultOpenWebApp =
  OpenWebApp
    { chat_id :: Maybe Int
chat_id           = Maybe Int
forall a. Maybe a
Nothing
    , bot_user_id :: Maybe Int
bot_user_id       = Maybe Int
forall a. Maybe a
Nothing
    , url :: Maybe Text
url               = Maybe Text
forall a. Maybe a
Nothing
    , theme :: Maybe ThemeParameters
theme             = Maybe ThemeParameters
forall a. Maybe a
Nothing
    , application_name :: Maybe Text
application_name  = Maybe Text
forall a. Maybe a
Nothing
    , message_thread_id :: Maybe Int
message_thread_id = Maybe Int
forall a. Maybe a
Nothing
    , reply_to :: Maybe InputMessageReplyTo
reply_to          = Maybe InputMessageReplyTo
forall a. Maybe a
Nothing
    }