module TD.Data.ChatBackground
  (ChatBackground(..)) 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

data ChatBackground
  = ChatBackground -- ^ Describes a background set for a specific chat
    { ChatBackground -> Maybe Background
background         :: Maybe Background.Background -- ^ The background
    , ChatBackground -> Maybe Int
dark_theme_dimming :: Maybe Int                   -- ^ Dimming of the background in dark themes, as a percentage; 0-100. Applied only to Wallpaper and Fill types of background
    }
  deriving (ChatBackground -> ChatBackground -> Bool
(ChatBackground -> ChatBackground -> Bool)
-> (ChatBackground -> ChatBackground -> Bool) -> Eq ChatBackground
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatBackground -> ChatBackground -> Bool
== :: ChatBackground -> ChatBackground -> Bool
$c/= :: ChatBackground -> ChatBackground -> Bool
/= :: ChatBackground -> ChatBackground -> Bool
Eq, Int -> ChatBackground -> ShowS
[ChatBackground] -> ShowS
ChatBackground -> String
(Int -> ChatBackground -> ShowS)
-> (ChatBackground -> String)
-> ([ChatBackground] -> ShowS)
-> Show ChatBackground
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatBackground -> ShowS
showsPrec :: Int -> ChatBackground -> ShowS
$cshow :: ChatBackground -> String
show :: ChatBackground -> String
$cshowList :: [ChatBackground] -> ShowS
showList :: [ChatBackground] -> ShowS
Show)

instance I.ShortShow ChatBackground where
  shortShow :: ChatBackground -> String
shortShow ChatBackground
    { background :: ChatBackground -> Maybe Background
background         = Maybe Background
background_
    , dark_theme_dimming :: ChatBackground -> Maybe Int
dark_theme_dimming = Maybe Int
dark_theme_dimming_
    }
      = String
"ChatBackground"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"background"         String -> Maybe Background -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Background
background_
        , String
"dark_theme_dimming" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
dark_theme_dimming_
        ]

instance AT.FromJSON ChatBackground where
  parseJSON :: Value -> Parser ChatBackground
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
"chatBackground" -> Value -> Parser ChatBackground
parseChatBackground Value
v
      String
_                -> Parser ChatBackground
forall a. Monoid a => a
mempty
    
    where
      parseChatBackground :: A.Value -> AT.Parser ChatBackground
      parseChatBackground :: Value -> Parser ChatBackground
parseChatBackground = String
-> (Object -> Parser ChatBackground)
-> Value
-> Parser ChatBackground
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatBackground" ((Object -> Parser ChatBackground)
 -> Value -> Parser ChatBackground)
-> (Object -> Parser ChatBackground)
-> Value
-> Parser ChatBackground
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Background
background_         <- Object
o Object -> Key -> Parser (Maybe Background)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"background"
        Maybe Int
dark_theme_dimming_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"dark_theme_dimming"
        ChatBackground -> Parser ChatBackground
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatBackground -> Parser ChatBackground)
-> ChatBackground -> Parser ChatBackground
forall a b. (a -> b) -> a -> b
$ ChatBackground
          { background :: Maybe Background
background         = Maybe Background
background_
          , dark_theme_dimming :: Maybe Int
dark_theme_dimming = Maybe Int
dark_theme_dimming_
          }
  parseJSON Value
_ = Parser ChatBackground
forall a. Monoid a => a
mempty