module TD.Data.ChatTheme
  (ChatTheme(..)) 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 ChatTheme
  = ChatTheme -- ^ Describes a chat theme
    { ChatTheme -> Maybe Text
name           :: Maybe T.Text                      -- ^ Theme name
    , ChatTheme -> Maybe ThemeSettings
light_settings :: Maybe ThemeSettings.ThemeSettings -- ^ Theme settings for a light chat theme
    , ChatTheme -> Maybe ThemeSettings
dark_settings  :: Maybe ThemeSettings.ThemeSettings -- ^ Theme settings for a dark chat theme
    }
  deriving (ChatTheme -> ChatTheme -> Bool
(ChatTheme -> ChatTheme -> Bool)
-> (ChatTheme -> ChatTheme -> Bool) -> Eq ChatTheme
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatTheme -> ChatTheme -> Bool
== :: ChatTheme -> ChatTheme -> Bool
$c/= :: ChatTheme -> ChatTheme -> Bool
/= :: ChatTheme -> ChatTheme -> Bool
Eq, Int -> ChatTheme -> ShowS
[ChatTheme] -> ShowS
ChatTheme -> String
(Int -> ChatTheme -> ShowS)
-> (ChatTheme -> String)
-> ([ChatTheme] -> ShowS)
-> Show ChatTheme
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatTheme -> ShowS
showsPrec :: Int -> ChatTheme -> ShowS
$cshow :: ChatTheme -> String
show :: ChatTheme -> String
$cshowList :: [ChatTheme] -> ShowS
showList :: [ChatTheme] -> ShowS
Show)

instance I.ShortShow ChatTheme where
  shortShow :: ChatTheme -> String
shortShow ChatTheme
    { name :: ChatTheme -> Maybe Text
name           = Maybe Text
name_
    , light_settings :: ChatTheme -> Maybe ThemeSettings
light_settings = Maybe ThemeSettings
light_settings_
    , dark_settings :: ChatTheme -> Maybe ThemeSettings
dark_settings  = Maybe ThemeSettings
dark_settings_
    }
      = String
"ChatTheme"
        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 ChatTheme where
  parseJSON :: Value -> Parser ChatTheme
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
"chatTheme" -> Value -> Parser ChatTheme
parseChatTheme Value
v
      String
_           -> Parser ChatTheme
forall a. Monoid a => a
mempty
    
    where
      parseChatTheme :: A.Value -> AT.Parser ChatTheme
      parseChatTheme :: Value -> Parser ChatTheme
parseChatTheme = String -> (Object -> Parser ChatTheme) -> Value -> Parser ChatTheme
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatTheme" ((Object -> Parser ChatTheme) -> Value -> Parser ChatTheme)
-> (Object -> Parser ChatTheme) -> Value -> Parser ChatTheme
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"
        ChatTheme -> Parser ChatTheme
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatTheme -> Parser ChatTheme) -> ChatTheme -> Parser ChatTheme
forall a b. (a -> b) -> a -> b
$ ChatTheme
          { 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 ChatTheme
forall a. Monoid a => a
mempty