module TD.Data.ThemeSettings
(ThemeSettings(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.Background as Background
import qualified TD.Data.BackgroundFill as BackgroundFill
data ThemeSettings
= ThemeSettings
{ ThemeSettings -> Maybe Int
accent_color :: Maybe Int
, ThemeSettings -> Maybe Background
background :: Maybe Background.Background
, ThemeSettings -> Maybe BackgroundFill
outgoing_message_fill :: Maybe BackgroundFill.BackgroundFill
, ThemeSettings -> Maybe Bool
animate_outgoing_message_fill :: Maybe Bool
, ThemeSettings -> Maybe Int
outgoing_message_accent_color :: Maybe Int
}
deriving (ThemeSettings -> ThemeSettings -> Bool
(ThemeSettings -> ThemeSettings -> Bool)
-> (ThemeSettings -> ThemeSettings -> Bool) -> Eq ThemeSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ThemeSettings -> ThemeSettings -> Bool
== :: ThemeSettings -> ThemeSettings -> Bool
$c/= :: ThemeSettings -> ThemeSettings -> Bool
/= :: ThemeSettings -> ThemeSettings -> Bool
Eq, Int -> ThemeSettings -> ShowS
[ThemeSettings] -> ShowS
ThemeSettings -> String
(Int -> ThemeSettings -> ShowS)
-> (ThemeSettings -> String)
-> ([ThemeSettings] -> ShowS)
-> Show ThemeSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ThemeSettings -> ShowS
showsPrec :: Int -> ThemeSettings -> ShowS
$cshow :: ThemeSettings -> String
show :: ThemeSettings -> String
$cshowList :: [ThemeSettings] -> ShowS
showList :: [ThemeSettings] -> ShowS
Show)
instance I.ShortShow ThemeSettings where
shortShow :: ThemeSettings -> String
shortShow ThemeSettings
{ accent_color :: ThemeSettings -> Maybe Int
accent_color = Maybe Int
accent_color_
, background :: ThemeSettings -> Maybe Background
background = Maybe Background
background_
, outgoing_message_fill :: ThemeSettings -> Maybe BackgroundFill
outgoing_message_fill = Maybe BackgroundFill
outgoing_message_fill_
, animate_outgoing_message_fill :: ThemeSettings -> Maybe Bool
animate_outgoing_message_fill = Maybe Bool
animate_outgoing_message_fill_
, outgoing_message_accent_color :: ThemeSettings -> Maybe Int
outgoing_message_accent_color = Maybe Int
outgoing_message_accent_color_
}
= String
"ThemeSettings"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"accent_color" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
accent_color_
, String
"background" String -> Maybe Background -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Background
background_
, String
"outgoing_message_fill" String -> Maybe BackgroundFill -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe BackgroundFill
outgoing_message_fill_
, String
"animate_outgoing_message_fill" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
animate_outgoing_message_fill_
, String
"outgoing_message_accent_color" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
outgoing_message_accent_color_
]
instance AT.FromJSON ThemeSettings where
parseJSON :: Value -> Parser ThemeSettings
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
"themeSettings" -> Value -> Parser ThemeSettings
parseThemeSettings Value
v
String
_ -> Parser ThemeSettings
forall a. Monoid a => a
mempty
where
parseThemeSettings :: A.Value -> AT.Parser ThemeSettings
parseThemeSettings :: Value -> Parser ThemeSettings
parseThemeSettings = String
-> (Object -> Parser ThemeSettings)
-> Value
-> Parser ThemeSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ThemeSettings" ((Object -> Parser ThemeSettings) -> Value -> Parser ThemeSettings)
-> (Object -> Parser ThemeSettings)
-> Value
-> Parser ThemeSettings
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
accent_color_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"accent_color"
Maybe Background
background_ <- Object
o Object -> Key -> Parser (Maybe Background)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"background"
Maybe BackgroundFill
outgoing_message_fill_ <- Object
o Object -> Key -> Parser (Maybe BackgroundFill)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"outgoing_message_fill"
Maybe Bool
animate_outgoing_message_fill_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"animate_outgoing_message_fill"
Maybe Int
outgoing_message_accent_color_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"outgoing_message_accent_color"
ThemeSettings -> Parser ThemeSettings
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ThemeSettings -> Parser ThemeSettings)
-> ThemeSettings -> Parser ThemeSettings
forall a b. (a -> b) -> a -> b
$ ThemeSettings
{ accent_color :: Maybe Int
accent_color = Maybe Int
accent_color_
, background :: Maybe Background
background = Maybe Background
background_
, outgoing_message_fill :: Maybe BackgroundFill
outgoing_message_fill = Maybe BackgroundFill
outgoing_message_fill_
, animate_outgoing_message_fill :: Maybe Bool
animate_outgoing_message_fill = Maybe Bool
animate_outgoing_message_fill_
, outgoing_message_accent_color :: Maybe Int
outgoing_message_accent_color = Maybe Int
outgoing_message_accent_color_
}
parseJSON Value
_ = Parser ThemeSettings
forall a. Monoid a => a
mempty