module TD.Data.TextCompositionParameters
  ( TextCompositionParameters(..)    
  , defaultTextCompositionParameters 
  ) 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 TextCompositionParameters
  = TextCompositionParameters -- ^ Describes parameters of text composition with AI
    { TextCompositionParameters -> Maybe Text
translate_to_language_code :: Maybe T.Text -- ^ Language code to which the text will be translated; may be empty if none. See translateText.to_language_code for the list of supported values
    , TextCompositionParameters -> Maybe Text
style_name                 :: Maybe T.Text -- ^ Name of the style of the resulting text; may be empty if none. Handle updateTextCompositionStyles to get the list of supported styles
    , TextCompositionParameters -> Maybe Bool
add_emojis                 :: Maybe Bool   -- ^ True, if emoji will be added to the text
    , TextCompositionParameters -> Maybe Bool
fix_text                   :: Maybe Bool   -- ^ True, if the text will be fixed in the same way as by fixTextWithAi
    }
  deriving (TextCompositionParameters -> TextCompositionParameters -> Bool
(TextCompositionParameters -> TextCompositionParameters -> Bool)
-> (TextCompositionParameters -> TextCompositionParameters -> Bool)
-> Eq TextCompositionParameters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextCompositionParameters -> TextCompositionParameters -> Bool
== :: TextCompositionParameters -> TextCompositionParameters -> Bool
$c/= :: TextCompositionParameters -> TextCompositionParameters -> Bool
/= :: TextCompositionParameters -> TextCompositionParameters -> Bool
Eq, Int -> TextCompositionParameters -> ShowS
[TextCompositionParameters] -> ShowS
TextCompositionParameters -> String
(Int -> TextCompositionParameters -> ShowS)
-> (TextCompositionParameters -> String)
-> ([TextCompositionParameters] -> ShowS)
-> Show TextCompositionParameters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextCompositionParameters -> ShowS
showsPrec :: Int -> TextCompositionParameters -> ShowS
$cshow :: TextCompositionParameters -> String
show :: TextCompositionParameters -> String
$cshowList :: [TextCompositionParameters] -> ShowS
showList :: [TextCompositionParameters] -> ShowS
Show)

instance I.ShortShow TextCompositionParameters where
  shortShow :: TextCompositionParameters -> String
shortShow TextCompositionParameters
    { translate_to_language_code :: TextCompositionParameters -> Maybe Text
translate_to_language_code = Maybe Text
translate_to_language_code_
    , style_name :: TextCompositionParameters -> Maybe Text
style_name                 = Maybe Text
style_name_
    , add_emojis :: TextCompositionParameters -> Maybe Bool
add_emojis                 = Maybe Bool
add_emojis_
    , fix_text :: TextCompositionParameters -> Maybe Bool
fix_text                   = Maybe Bool
fix_text_
    }
      = String
"TextCompositionParameters"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"translate_to_language_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
translate_to_language_code_
        , String
"style_name"                 String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
style_name_
        , String
"add_emojis"                 String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
add_emojis_
        , String
"fix_text"                   String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
fix_text_
        ]

instance AT.FromJSON TextCompositionParameters where
  parseJSON :: Value -> Parser TextCompositionParameters
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
"textCompositionParameters" -> Value -> Parser TextCompositionParameters
parseTextCompositionParameters Value
v
      String
_                           -> Parser TextCompositionParameters
forall a. Monoid a => a
mempty
    
    where
      parseTextCompositionParameters :: A.Value -> AT.Parser TextCompositionParameters
      parseTextCompositionParameters :: Value -> Parser TextCompositionParameters
parseTextCompositionParameters = String
-> (Object -> Parser TextCompositionParameters)
-> Value
-> Parser TextCompositionParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TextCompositionParameters" ((Object -> Parser TextCompositionParameters)
 -> Value -> Parser TextCompositionParameters)
-> (Object -> Parser TextCompositionParameters)
-> Value
-> Parser TextCompositionParameters
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
translate_to_language_code_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"translate_to_language_code"
        Maybe Text
style_name_                 <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"style_name"
        Maybe Bool
add_emojis_                 <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"add_emojis"
        Maybe Bool
fix_text_                   <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"fix_text"
        TextCompositionParameters -> Parser TextCompositionParameters
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TextCompositionParameters -> Parser TextCompositionParameters)
-> TextCompositionParameters -> Parser TextCompositionParameters
forall a b. (a -> b) -> a -> b
$ TextCompositionParameters
          { translate_to_language_code :: Maybe Text
translate_to_language_code = Maybe Text
translate_to_language_code_
          , style_name :: Maybe Text
style_name                 = Maybe Text
style_name_
          , add_emojis :: Maybe Bool
add_emojis                 = Maybe Bool
add_emojis_
          , fix_text :: Maybe Bool
fix_text                   = Maybe Bool
fix_text_
          }
  parseJSON Value
_ = Parser TextCompositionParameters
forall a. Monoid a => a
mempty

instance AT.ToJSON TextCompositionParameters where
  toJSON :: TextCompositionParameters -> Value
toJSON TextCompositionParameters
    { translate_to_language_code :: TextCompositionParameters -> Maybe Text
translate_to_language_code = Maybe Text
translate_to_language_code_
    , style_name :: TextCompositionParameters -> Maybe Text
style_name                 = Maybe Text
style_name_
    , add_emojis :: TextCompositionParameters -> Maybe Bool
add_emojis                 = Maybe Bool
add_emojis_
    , fix_text :: TextCompositionParameters -> Maybe Bool
fix_text                   = Maybe Bool
fix_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
"textCompositionParameters"
        , Key
"translate_to_language_code" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
translate_to_language_code_
        , Key
"style_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
style_name_
        , Key
"add_emojis"                 Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
add_emojis_
        , Key
"fix_text"                   Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
fix_text_
        ]

defaultTextCompositionParameters :: TextCompositionParameters
defaultTextCompositionParameters :: TextCompositionParameters
defaultTextCompositionParameters =
  TextCompositionParameters
    { translate_to_language_code :: Maybe Text
translate_to_language_code = Maybe Text
forall a. Maybe a
Nothing
    , style_name :: Maybe Text
style_name                 = Maybe Text
forall a. Maybe a
Nothing
    , add_emojis :: Maybe Bool
add_emojis                 = Maybe Bool
forall a. Maybe a
Nothing
    , fix_text :: Maybe Bool
fix_text                   = Maybe Bool
forall a. Maybe a
Nothing
    }