module TD.Query.ParseMarkdown
  (ParseMarkdown(..)
  ) 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

-- | Parses Markdown entities in a human-friendly format, ignoring markup errors. Can be called synchronously. Returns 'TD.Data.FormattedText.FormattedText'
data ParseMarkdown
  = ParseMarkdown
    { ParseMarkdown -> Maybe FormattedText
text :: Maybe FormattedText.FormattedText -- ^ The text to parse. For example, "__italic__ ~~strikethrough~~ ||spoiler|| **bold** `code` ```pre``` __[italic__ text_url](telegram.org) __italic**bold italic__bold**"
    }
  deriving (ParseMarkdown -> ParseMarkdown -> Bool
(ParseMarkdown -> ParseMarkdown -> Bool)
-> (ParseMarkdown -> ParseMarkdown -> Bool) -> Eq ParseMarkdown
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ParseMarkdown -> ParseMarkdown -> Bool
== :: ParseMarkdown -> ParseMarkdown -> Bool
$c/= :: ParseMarkdown -> ParseMarkdown -> Bool
/= :: ParseMarkdown -> ParseMarkdown -> Bool
Eq, Int -> ParseMarkdown -> ShowS
[ParseMarkdown] -> ShowS
ParseMarkdown -> String
(Int -> ParseMarkdown -> ShowS)
-> (ParseMarkdown -> String)
-> ([ParseMarkdown] -> ShowS)
-> Show ParseMarkdown
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParseMarkdown -> ShowS
showsPrec :: Int -> ParseMarkdown -> ShowS
$cshow :: ParseMarkdown -> String
show :: ParseMarkdown -> String
$cshowList :: [ParseMarkdown] -> ShowS
showList :: [ParseMarkdown] -> ShowS
Show)

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

instance AT.ToJSON ParseMarkdown where
  toJSON :: ParseMarkdown -> Value
toJSON
    ParseMarkdown
      { text :: ParseMarkdown -> Maybe FormattedText
text = Maybe FormattedText
text_
      }
        = [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
"parseMarkdown"
          , Key
"text"  Key -> Maybe FormattedText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FormattedText
text_
          ]