module TD.Data.RichText
  (RichText(..)) 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.Document as Document

-- | Describes a formatted text object
data RichText
  = RichTextPlain -- ^ A plain text
    { RichText -> Maybe Text
text :: Maybe T.Text -- ^ Text
    }
  | RichTextBold -- ^ A bold rich text
    { RichText -> Maybe RichText
_text :: Maybe RichText -- ^ Text
    }
  | RichTextItalic -- ^ An italicized rich text
    { _text :: Maybe RichText -- ^ Text
    }
  | RichTextUnderline -- ^ An underlined rich text
    { _text :: Maybe RichText -- ^ Text
    }
  | RichTextStrikethrough -- ^ A strikethrough rich text
    { _text :: Maybe RichText -- ^ Text
    }
  | RichTextFixed -- ^ A fixed-width rich text
    { _text :: Maybe RichText -- ^ Text
    }
  | RichTextUrl -- ^ A rich text URL link
    { _text     :: Maybe RichText -- ^ Text
    , RichText -> Maybe Text
url       :: Maybe T.Text   -- ^ URL
    , RichText -> Maybe Bool
is_cached :: Maybe Bool     -- ^ True, if the URL has cached instant view server-side
    }
  | RichTextEmailAddress -- ^ A rich text email link
    { _text         :: Maybe RichText -- ^ Text
    , RichText -> Maybe Text
email_address :: Maybe T.Text   -- ^ Email address
    }
  | RichTextSubscript -- ^ A subscript rich text
    { _text :: Maybe RichText -- ^ Text
    }
  | RichTextSuperscript -- ^ A superscript rich text
    { _text :: Maybe RichText -- ^ Text
    }
  | RichTextMarked -- ^ A marked rich text
    { _text :: Maybe RichText -- ^ Text
    }
  | RichTextPhoneNumber -- ^ A rich text phone number
    { _text        :: Maybe RichText -- ^ Text
    , RichText -> Maybe Text
phone_number :: Maybe T.Text   -- ^ Phone number
    }
  | RichTextIcon -- ^ A small image inside the text
    { RichText -> Maybe Document
document :: Maybe Document.Document -- ^ The image represented as a document. The image can be in GIF, JPEG or PNG format
    , RichText -> Maybe Int
width    :: Maybe Int               -- ^ Width of a bounding box in which the image must be shown; 0 if unknown
    , RichText -> Maybe Int
height   :: Maybe Int               -- ^ Height of a bounding box in which the image must be shown; 0 if unknown
    }
  | RichTextReference -- ^ A reference to a richTexts object on the same page
    { _text       :: Maybe RichText -- ^ The text
    , RichText -> Maybe Text
anchor_name :: Maybe T.Text   -- ^ The name of a richTextAnchor object, which is the first element of the target richTexts object
    , url         :: Maybe T.Text   -- ^ An HTTP URL, opening the reference
    }
  | RichTextAnchor -- ^ An anchor
    { RichText -> Maybe Text
name :: Maybe T.Text -- ^ Anchor name
    }
  | RichTextAnchorLink -- ^ A link to an anchor on the same page
    { _text       :: Maybe RichText -- ^ The link text
    , anchor_name :: Maybe T.Text   -- ^ The anchor name. If the name is empty, the link must bring back to top
    , url         :: Maybe T.Text   -- ^ An HTTP URL, opening the anchor
    }
  | RichTexts -- ^ A concatenation of rich texts
    { RichText -> Maybe [RichText]
texts :: Maybe [RichText] -- ^ Texts
    }
  deriving (RichText -> RichText -> Bool
(RichText -> RichText -> Bool)
-> (RichText -> RichText -> Bool) -> Eq RichText
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RichText -> RichText -> Bool
== :: RichText -> RichText -> Bool
$c/= :: RichText -> RichText -> Bool
/= :: RichText -> RichText -> Bool
Eq, Int -> RichText -> ShowS
[RichText] -> ShowS
RichText -> String
(Int -> RichText -> ShowS)
-> (RichText -> String) -> ([RichText] -> ShowS) -> Show RichText
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RichText -> ShowS
showsPrec :: Int -> RichText -> ShowS
$cshow :: RichText -> String
show :: RichText -> String
$cshowList :: [RichText] -> ShowS
showList :: [RichText] -> ShowS
Show)

instance I.ShortShow RichText where
  shortShow :: RichText -> String
shortShow RichTextPlain
    { text :: RichText -> Maybe Text
text = Maybe Text
text_
    }
      = String
"RichTextPlain"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"text" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
text_
        ]
  shortShow RichTextBold
    { _text :: RichText -> Maybe RichText
_text = Maybe RichText
_text_
    }
      = String
"RichTextBold"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text" String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        ]
  shortShow RichTextItalic
    { _text :: RichText -> Maybe RichText
_text = Maybe RichText
_text_
    }
      = String
"RichTextItalic"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text" String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        ]
  shortShow RichTextUnderline
    { _text :: RichText -> Maybe RichText
_text = Maybe RichText
_text_
    }
      = String
"RichTextUnderline"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text" String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        ]
  shortShow RichTextStrikethrough
    { _text :: RichText -> Maybe RichText
_text = Maybe RichText
_text_
    }
      = String
"RichTextStrikethrough"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text" String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        ]
  shortShow RichTextFixed
    { _text :: RichText -> Maybe RichText
_text = Maybe RichText
_text_
    }
      = String
"RichTextFixed"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text" String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        ]
  shortShow RichTextUrl
    { _text :: RichText -> Maybe RichText
_text     = Maybe RichText
_text_
    , url :: RichText -> Maybe Text
url       = Maybe Text
url_
    , is_cached :: RichText -> Maybe Bool
is_cached = Maybe Bool
is_cached_
    }
      = String
"RichTextUrl"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text"     String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        , String
"url"       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
        , String
"is_cached" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_cached_
        ]
  shortShow RichTextEmailAddress
    { _text :: RichText -> Maybe RichText
_text         = Maybe RichText
_text_
    , email_address :: RichText -> Maybe Text
email_address = Maybe Text
email_address_
    }
      = String
"RichTextEmailAddress"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text"         String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        , String
"email_address" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
email_address_
        ]
  shortShow RichTextSubscript
    { _text :: RichText -> Maybe RichText
_text = Maybe RichText
_text_
    }
      = String
"RichTextSubscript"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text" String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        ]
  shortShow RichTextSuperscript
    { _text :: RichText -> Maybe RichText
_text = Maybe RichText
_text_
    }
      = String
"RichTextSuperscript"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text" String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        ]
  shortShow RichTextMarked
    { _text :: RichText -> Maybe RichText
_text = Maybe RichText
_text_
    }
      = String
"RichTextMarked"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text" String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        ]
  shortShow RichTextPhoneNumber
    { _text :: RichText -> Maybe RichText
_text        = Maybe RichText
_text_
    , phone_number :: RichText -> Maybe Text
phone_number = Maybe Text
phone_number_
    }
      = String
"RichTextPhoneNumber"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text"        String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        , String
"phone_number" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
phone_number_
        ]
  shortShow RichTextIcon
    { document :: RichText -> Maybe Document
document = Maybe Document
document_
    , width :: RichText -> Maybe Int
width    = Maybe Int
width_
    , height :: RichText -> Maybe Int
height   = Maybe Int
height_
    }
      = String
"RichTextIcon"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"document" String -> Maybe Document -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Document
document_
        , String
"width"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
width_
        , String
"height"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
height_
        ]
  shortShow RichTextReference
    { _text :: RichText -> Maybe RichText
_text       = Maybe RichText
_text_
    , anchor_name :: RichText -> Maybe Text
anchor_name = Maybe Text
anchor_name_
    , url :: RichText -> Maybe Text
url         = Maybe Text
url_
    }
      = String
"RichTextReference"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text"       String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        , String
"anchor_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
anchor_name_
        , String
"url"         String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
        ]
  shortShow RichTextAnchor
    { name :: RichText -> Maybe Text
name = Maybe Text
name_
    }
      = String
"RichTextAnchor"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
        ]
  shortShow RichTextAnchorLink
    { _text :: RichText -> Maybe RichText
_text       = Maybe RichText
_text_
    , anchor_name :: RichText -> Maybe Text
anchor_name = Maybe Text
anchor_name_
    , url :: RichText -> Maybe Text
url         = Maybe Text
url_
    }
      = String
"RichTextAnchorLink"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_text"       String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
_text_
        , String
"anchor_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
anchor_name_
        , String
"url"         String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
        ]
  shortShow RichTexts
    { texts :: RichText -> Maybe [RichText]
texts = Maybe [RichText]
texts_
    }
      = String
"RichTexts"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"texts" String -> Maybe [RichText] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [RichText]
texts_
        ]

instance AT.FromJSON RichText where
  parseJSON :: Value -> Parser RichText
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
"richTextPlain"         -> Value -> Parser RichText
parseRichTextPlain Value
v
      String
"richTextBold"          -> Value -> Parser RichText
parseRichTextBold Value
v
      String
"richTextItalic"        -> Value -> Parser RichText
parseRichTextItalic Value
v
      String
"richTextUnderline"     -> Value -> Parser RichText
parseRichTextUnderline Value
v
      String
"richTextStrikethrough" -> Value -> Parser RichText
parseRichTextStrikethrough Value
v
      String
"richTextFixed"         -> Value -> Parser RichText
parseRichTextFixed Value
v
      String
"richTextUrl"           -> Value -> Parser RichText
parseRichTextUrl Value
v
      String
"richTextEmailAddress"  -> Value -> Parser RichText
parseRichTextEmailAddress Value
v
      String
"richTextSubscript"     -> Value -> Parser RichText
parseRichTextSubscript Value
v
      String
"richTextSuperscript"   -> Value -> Parser RichText
parseRichTextSuperscript Value
v
      String
"richTextMarked"        -> Value -> Parser RichText
parseRichTextMarked Value
v
      String
"richTextPhoneNumber"   -> Value -> Parser RichText
parseRichTextPhoneNumber Value
v
      String
"richTextIcon"          -> Value -> Parser RichText
parseRichTextIcon Value
v
      String
"richTextReference"     -> Value -> Parser RichText
parseRichTextReference Value
v
      String
"richTextAnchor"        -> Value -> Parser RichText
parseRichTextAnchor Value
v
      String
"richTextAnchorLink"    -> Value -> Parser RichText
parseRichTextAnchorLink Value
v
      String
"richTexts"             -> Value -> Parser RichText
parseRichTexts Value
v
      String
_                       -> Parser RichText
forall a. Monoid a => a
mempty
    
    where
      parseRichTextPlain :: A.Value -> AT.Parser RichText
      parseRichTextPlain :: Value -> Parser RichText
parseRichTextPlain = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextPlain" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
text_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextPlain
          { text :: Maybe Text
text = Maybe Text
text_
          }
      parseRichTextBold :: A.Value -> AT.Parser RichText
      parseRichTextBold :: Value -> Parser RichText
parseRichTextBold = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextBold" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_ <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextBold
          { _text :: Maybe RichText
_text = Maybe RichText
_text_
          }
      parseRichTextItalic :: A.Value -> AT.Parser RichText
      parseRichTextItalic :: Value -> Parser RichText
parseRichTextItalic = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextItalic" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_ <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextItalic
          { _text :: Maybe RichText
_text = Maybe RichText
_text_
          }
      parseRichTextUnderline :: A.Value -> AT.Parser RichText
      parseRichTextUnderline :: Value -> Parser RichText
parseRichTextUnderline = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextUnderline" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_ <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextUnderline
          { _text :: Maybe RichText
_text = Maybe RichText
_text_
          }
      parseRichTextStrikethrough :: A.Value -> AT.Parser RichText
      parseRichTextStrikethrough :: Value -> Parser RichText
parseRichTextStrikethrough = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextStrikethrough" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_ <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextStrikethrough
          { _text :: Maybe RichText
_text = Maybe RichText
_text_
          }
      parseRichTextFixed :: A.Value -> AT.Parser RichText
      parseRichTextFixed :: Value -> Parser RichText
parseRichTextFixed = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextFixed" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_ <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextFixed
          { _text :: Maybe RichText
_text = Maybe RichText
_text_
          }
      parseRichTextUrl :: A.Value -> AT.Parser RichText
      parseRichTextUrl :: Value -> Parser RichText
parseRichTextUrl = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextUrl" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_     <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe Text
url_       <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"url"
        Maybe Bool
is_cached_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_cached"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextUrl
          { _text :: Maybe RichText
_text     = Maybe RichText
_text_
          , url :: Maybe Text
url       = Maybe Text
url_
          , is_cached :: Maybe Bool
is_cached = Maybe Bool
is_cached_
          }
      parseRichTextEmailAddress :: A.Value -> AT.Parser RichText
      parseRichTextEmailAddress :: Value -> Parser RichText
parseRichTextEmailAddress = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextEmailAddress" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_         <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe Text
email_address_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"email_address"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextEmailAddress
          { _text :: Maybe RichText
_text         = Maybe RichText
_text_
          , email_address :: Maybe Text
email_address = Maybe Text
email_address_
          }
      parseRichTextSubscript :: A.Value -> AT.Parser RichText
      parseRichTextSubscript :: Value -> Parser RichText
parseRichTextSubscript = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextSubscript" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_ <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextSubscript
          { _text :: Maybe RichText
_text = Maybe RichText
_text_
          }
      parseRichTextSuperscript :: A.Value -> AT.Parser RichText
      parseRichTextSuperscript :: Value -> Parser RichText
parseRichTextSuperscript = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextSuperscript" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_ <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextSuperscript
          { _text :: Maybe RichText
_text = Maybe RichText
_text_
          }
      parseRichTextMarked :: A.Value -> AT.Parser RichText
      parseRichTextMarked :: Value -> Parser RichText
parseRichTextMarked = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextMarked" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_ <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextMarked
          { _text :: Maybe RichText
_text = Maybe RichText
_text_
          }
      parseRichTextPhoneNumber :: A.Value -> AT.Parser RichText
      parseRichTextPhoneNumber :: Value -> Parser RichText
parseRichTextPhoneNumber = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextPhoneNumber" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_        <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe Text
phone_number_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"phone_number"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextPhoneNumber
          { _text :: Maybe RichText
_text        = Maybe RichText
_text_
          , phone_number :: Maybe Text
phone_number = Maybe Text
phone_number_
          }
      parseRichTextIcon :: A.Value -> AT.Parser RichText
      parseRichTextIcon :: Value -> Parser RichText
parseRichTextIcon = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextIcon" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Document
document_ <- Object
o Object -> Key -> Parser (Maybe Document)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"document"
        Maybe Int
width_    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"width"
        Maybe Int
height_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"height"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextIcon
          { document :: Maybe Document
document = Maybe Document
document_
          , width :: Maybe Int
width    = Maybe Int
width_
          , height :: Maybe Int
height   = Maybe Int
height_
          }
      parseRichTextReference :: A.Value -> AT.Parser RichText
      parseRichTextReference :: Value -> Parser RichText
parseRichTextReference = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextReference" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_       <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe Text
anchor_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"anchor_name"
        Maybe Text
url_         <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"url"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextReference
          { _text :: Maybe RichText
_text       = Maybe RichText
_text_
          , anchor_name :: Maybe Text
anchor_name = Maybe Text
anchor_name_
          , url :: Maybe Text
url         = Maybe Text
url_
          }
      parseRichTextAnchor :: A.Value -> AT.Parser RichText
      parseRichTextAnchor :: Value -> Parser RichText
parseRichTextAnchor = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextAnchor" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"name"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextAnchor
          { name :: Maybe Text
name = Maybe Text
name_
          }
      parseRichTextAnchorLink :: A.Value -> AT.Parser RichText
      parseRichTextAnchorLink :: Value -> Parser RichText
parseRichTextAnchorLink = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTextAnchorLink" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
_text_       <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe Text
anchor_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"anchor_name"
        Maybe Text
url_         <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"url"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTextAnchorLink
          { _text :: Maybe RichText
_text       = Maybe RichText
_text_
          , anchor_name :: Maybe Text
anchor_name = Maybe Text
anchor_name_
          , url :: Maybe Text
url         = Maybe Text
url_
          }
      parseRichTexts :: A.Value -> AT.Parser RichText
      parseRichTexts :: Value -> Parser RichText
parseRichTexts = String -> (Object -> Parser RichText) -> Value -> Parser RichText
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RichTexts" ((Object -> Parser RichText) -> Value -> Parser RichText)
-> (Object -> Parser RichText) -> Value -> Parser RichText
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [RichText]
texts_ <- Object
o Object -> Key -> Parser (Maybe [RichText])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"texts"
        RichText -> Parser RichText
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RichText -> Parser RichText) -> RichText -> Parser RichText
forall a b. (a -> b) -> a -> b
$ RichTexts
          { texts :: Maybe [RichText]
texts = Maybe [RichText]
texts_
          }
  parseJSON Value
_ = Parser RichText
forall a. Monoid a => a
mempty