module TD.Data.EmojiChatTheme
  (EmojiChatTheme(..)) 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.ThemeSettings as ThemeSettings

data EmojiChatTheme
  = EmojiChatTheme -- ^ Describes a chat theme based on an emoji
    { EmojiChatTheme -> Maybe Text
name           :: Maybe T.Text                      -- ^ Theme name
    , EmojiChatTheme -> Maybe ThemeSettings
light_settings :: Maybe ThemeSettings.ThemeSettings -- ^ Theme settings for a light chat theme
    , EmojiChatTheme -> Maybe ThemeSettings
dark_settings  :: Maybe ThemeSettings.ThemeSettings -- ^ Theme settings for a dark chat theme
    }
  deriving (EmojiChatTheme -> EmojiChatTheme -> Bool
(EmojiChatTheme -> EmojiChatTheme -> Bool)
-> (EmojiChatTheme -> EmojiChatTheme -> Bool) -> Eq EmojiChatTheme
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EmojiChatTheme -> EmojiChatTheme -> Bool
== :: EmojiChatTheme -> EmojiChatTheme -> Bool
$c/= :: EmojiChatTheme -> EmojiChatTheme -> Bool
/= :: EmojiChatTheme -> EmojiChatTheme -> Bool
Eq, Int -> EmojiChatTheme -> ShowS
[EmojiChatTheme] -> ShowS
EmojiChatTheme -> String
(Int -> EmojiChatTheme -> ShowS)
-> (EmojiChatTheme -> String)
-> ([EmojiChatTheme] -> ShowS)
-> Show EmojiChatTheme
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EmojiChatTheme -> ShowS
showsPrec :: Int -> EmojiChatTheme -> ShowS
$cshow :: EmojiChatTheme -> String
show :: EmojiChatTheme -> String
$cshowList :: [EmojiChatTheme] -> ShowS
showList :: [EmojiChatTheme] -> ShowS
Show)

instance I.ShortShow EmojiChatTheme where
  shortShow :: EmojiChatTheme -> String
shortShow EmojiChatTheme
    { name :: EmojiChatTheme -> Maybe Text
name           = Maybe Text
name_
    , light_settings :: EmojiChatTheme -> Maybe ThemeSettings
light_settings = Maybe ThemeSettings
light_settings_
    , dark_settings :: EmojiChatTheme -> Maybe ThemeSettings
dark_settings  = Maybe ThemeSettings
dark_settings_
    }
      = String
"EmojiChatTheme"
        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
"light_settings" String -> Maybe ThemeSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ThemeSettings
light_settings_
        , String
"dark_settings"  String -> Maybe ThemeSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ThemeSettings
dark_settings_
        ]

instance AT.FromJSON EmojiChatTheme where
  parseJSON :: Value -> Parser EmojiChatTheme
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
"emojiChatTheme" -> Value -> Parser EmojiChatTheme
parseEmojiChatTheme Value
v
      String
_                -> Parser EmojiChatTheme
forall a. Monoid a => a
mempty
    
    where
      parseEmojiChatTheme :: A.Value -> AT.Parser EmojiChatTheme
      parseEmojiChatTheme :: Value -> Parser EmojiChatTheme
parseEmojiChatTheme = String
-> (Object -> Parser EmojiChatTheme)
-> Value
-> Parser EmojiChatTheme
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"EmojiChatTheme" ((Object -> Parser EmojiChatTheme)
 -> Value -> Parser EmojiChatTheme)
-> (Object -> Parser EmojiChatTheme)
-> Value
-> Parser EmojiChatTheme
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 ThemeSettings
light_settings_ <- Object
o Object -> Key -> Parser (Maybe ThemeSettings)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"light_settings"
        Maybe ThemeSettings
dark_settings_  <- Object
o Object -> Key -> Parser (Maybe ThemeSettings)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"dark_settings"
        EmojiChatTheme -> Parser EmojiChatTheme
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EmojiChatTheme -> Parser EmojiChatTheme)
-> EmojiChatTheme -> Parser EmojiChatTheme
forall a b. (a -> b) -> a -> b
$ EmojiChatTheme
          { name :: Maybe Text
name           = Maybe Text
name_
          , light_settings :: Maybe ThemeSettings
light_settings = Maybe ThemeSettings
light_settings_
          , dark_settings :: Maybe ThemeSettings
dark_settings  = Maybe ThemeSettings
dark_settings_
          }
  parseJSON Value
_ = Parser EmojiChatTheme
forall a. Monoid a => a
mempty