module TD.Data.TextCompositionStyle
  (TextCompositionStyle(..)) 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.TextCompositionStyleExample as TextCompositionStyleExample

data TextCompositionStyle
  = TextCompositionStyle -- ^ Describes a style that can be used to compose a text
    { TextCompositionStyle -> Maybe Text
name            :: Maybe T.Text                                                  -- ^ Name of the style
    , TextCompositionStyle -> Maybe Int
custom_emoji_id :: Maybe Int                                                     -- ^ Identifier of the custom emoji corresponding to the style; 0 if none
    , TextCompositionStyle -> Maybe Text
title           :: Maybe T.Text                                                  -- ^ Title of the style in the user application's language
    , TextCompositionStyle -> Maybe Bool
is_custom       :: Maybe Bool                                                    -- ^ True, if the style is created by a user
    , TextCompositionStyle -> Maybe Bool
is_creator      :: Maybe Bool                                                    -- ^ True, if the user is creator of the style
    , TextCompositionStyle -> Maybe Int
install_count   :: Maybe Int                                                     -- ^ Number of users that installed the style; for created custom styles only; 0 if unknown
    , TextCompositionStyle -> Maybe Text
prompt          :: Maybe T.Text                                                  -- ^ Prompt of the style; for created custom styles only
    , TextCompositionStyle -> Maybe Int
creator_user_id :: Maybe Int                                                     -- ^ User identifier of the creator of the style; 0 if none of unknown
    , TextCompositionStyle -> Maybe TextCompositionStyleExample
english_example :: Maybe TextCompositionStyleExample.TextCompositionStyleExample -- ^ Example of the style usage in English; may be null if unknown
    }
  deriving (TextCompositionStyle -> TextCompositionStyle -> Bool
(TextCompositionStyle -> TextCompositionStyle -> Bool)
-> (TextCompositionStyle -> TextCompositionStyle -> Bool)
-> Eq TextCompositionStyle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextCompositionStyle -> TextCompositionStyle -> Bool
== :: TextCompositionStyle -> TextCompositionStyle -> Bool
$c/= :: TextCompositionStyle -> TextCompositionStyle -> Bool
/= :: TextCompositionStyle -> TextCompositionStyle -> Bool
Eq, Int -> TextCompositionStyle -> ShowS
[TextCompositionStyle] -> ShowS
TextCompositionStyle -> String
(Int -> TextCompositionStyle -> ShowS)
-> (TextCompositionStyle -> String)
-> ([TextCompositionStyle] -> ShowS)
-> Show TextCompositionStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextCompositionStyle -> ShowS
showsPrec :: Int -> TextCompositionStyle -> ShowS
$cshow :: TextCompositionStyle -> String
show :: TextCompositionStyle -> String
$cshowList :: [TextCompositionStyle] -> ShowS
showList :: [TextCompositionStyle] -> ShowS
Show)

instance I.ShortShow TextCompositionStyle where
  shortShow :: TextCompositionStyle -> String
shortShow TextCompositionStyle
    { name :: TextCompositionStyle -> Maybe Text
name            = Maybe Text
name_
    , custom_emoji_id :: TextCompositionStyle -> Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
    , title :: TextCompositionStyle -> Maybe Text
title           = Maybe Text
title_
    , is_custom :: TextCompositionStyle -> Maybe Bool
is_custom       = Maybe Bool
is_custom_
    , is_creator :: TextCompositionStyle -> Maybe Bool
is_creator      = Maybe Bool
is_creator_
    , install_count :: TextCompositionStyle -> Maybe Int
install_count   = Maybe Int
install_count_
    , prompt :: TextCompositionStyle -> Maybe Text
prompt          = Maybe Text
prompt_
    , creator_user_id :: TextCompositionStyle -> Maybe Int
creator_user_id = Maybe Int
creator_user_id_
    , english_example :: TextCompositionStyle -> Maybe TextCompositionStyleExample
english_example = Maybe TextCompositionStyleExample
english_example_
    }
      = String
"TextCompositionStyle"
        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_
        , String
"custom_emoji_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
custom_emoji_id_
        , String
"title"           String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"is_custom"       String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_custom_
        , String
"is_creator"      String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_creator_
        , String
"install_count"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
install_count_
        , String
"prompt"          String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
prompt_
        , String
"creator_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
creator_user_id_
        , String
"english_example" String -> Maybe TextCompositionStyleExample -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe TextCompositionStyleExample
english_example_
        ]

instance AT.FromJSON TextCompositionStyle where
  parseJSON :: Value -> Parser TextCompositionStyle
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
"textCompositionStyle" -> Value -> Parser TextCompositionStyle
parseTextCompositionStyle Value
v
      String
_                      -> Parser TextCompositionStyle
forall a. Monoid a => a
mempty
    
    where
      parseTextCompositionStyle :: A.Value -> AT.Parser TextCompositionStyle
      parseTextCompositionStyle :: Value -> Parser TextCompositionStyle
parseTextCompositionStyle = String
-> (Object -> Parser TextCompositionStyle)
-> Value
-> Parser TextCompositionStyle
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TextCompositionStyle" ((Object -> Parser TextCompositionStyle)
 -> Value -> Parser TextCompositionStyle)
-> (Object -> Parser TextCompositionStyle)
-> Value
-> Parser TextCompositionStyle
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"
        Maybe Int
custom_emoji_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"custom_emoji_id"
        Maybe Text
title_           <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"title"
        Maybe Bool
is_custom_       <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_custom"
        Maybe Bool
is_creator_      <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_creator"
        Maybe Int
install_count_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"install_count"
        Maybe Text
prompt_          <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"prompt"
        Maybe Int
creator_user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"creator_user_id"
        Maybe TextCompositionStyleExample
english_example_ <- Object
o Object -> Key -> Parser (Maybe TextCompositionStyleExample)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"english_example"
        TextCompositionStyle -> Parser TextCompositionStyle
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TextCompositionStyle -> Parser TextCompositionStyle)
-> TextCompositionStyle -> Parser TextCompositionStyle
forall a b. (a -> b) -> a -> b
$ TextCompositionStyle
          { name :: Maybe Text
name            = Maybe Text
name_
          , custom_emoji_id :: Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
          , title :: Maybe Text
title           = Maybe Text
title_
          , is_custom :: Maybe Bool
is_custom       = Maybe Bool
is_custom_
          , is_creator :: Maybe Bool
is_creator      = Maybe Bool
is_creator_
          , install_count :: Maybe Int
install_count   = Maybe Int
install_count_
          , prompt :: Maybe Text
prompt          = Maybe Text
prompt_
          , creator_user_id :: Maybe Int
creator_user_id = Maybe Int
creator_user_id_
          , english_example :: Maybe TextCompositionStyleExample
english_example = Maybe TextCompositionStyleExample
english_example_
          }
  parseJSON Value
_ = Parser TextCompositionStyle
forall a. Monoid a => a
mempty