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.BuiltInTheme as BuiltInTheme
import qualified TD.Data.Background as Background
import qualified TD.Data.BackgroundFill as BackgroundFill

data ThemeSettings
  = ThemeSettings -- ^ Describes theme settings
    { ThemeSettings -> Maybe BuiltInTheme
base_theme                        :: Maybe BuiltInTheme.BuiltInTheme     -- ^ Base theme for this theme
    , ThemeSettings -> Maybe Int
accent_color                      :: Maybe Int                           -- ^ Theme accent color in ARGB format
    , ThemeSettings -> Maybe Background
background                        :: Maybe Background.Background         -- ^ The background to be used in chats; may be null
    , ThemeSettings -> Maybe BackgroundFill
outgoing_message_fill             :: Maybe BackgroundFill.BackgroundFill -- ^ The fill to be used as a background for outgoing messages; may be null if the fill from the base theme must be used instead
    , ThemeSettings -> Maybe Bool
animate_outgoing_message_fill     :: Maybe Bool                          -- ^ If true, the freeform gradient fill needs to be animated on every sent message
    , ThemeSettings -> Maybe Bool
has_outgoing_message_accent_color :: Maybe Bool                          -- ^ True, if there is chosen accent color for outgoing messages; otherwise, the color must be deduced from other theme settings
    , ThemeSettings -> Maybe Int
outgoing_message_accent_color     :: Maybe Int                           -- ^ Accent color of outgoing messages in ARGB format; must be ignored if has_outgoing_message_accent_color is false
    }
  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
    { base_theme :: ThemeSettings -> Maybe BuiltInTheme
base_theme                        = Maybe BuiltInTheme
base_theme_
    , 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_
    , has_outgoing_message_accent_color :: ThemeSettings -> Maybe Bool
has_outgoing_message_accent_color = Maybe Bool
has_outgoing_message_accent_color_
    , 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
"base_theme"                        String -> Maybe BuiltInTheme -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe BuiltInTheme
base_theme_
        , 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
"has_outgoing_message_accent_color" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_outgoing_message_accent_color_
        , 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 BuiltInTheme
base_theme_                        <- Object
o Object -> Key -> Parser (Maybe BuiltInTheme)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"base_theme"
        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 Bool
has_outgoing_message_accent_color_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"has_outgoing_message_accent_color"
        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
          { base_theme :: Maybe BuiltInTheme
base_theme                        = Maybe BuiltInTheme
base_theme_
          , 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_
          , has_outgoing_message_accent_color :: Maybe Bool
has_outgoing_message_accent_color = Maybe Bool
has_outgoing_message_accent_color_
          , 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