module TD.Data.AccentColor
  (AccentColor(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

data AccentColor
  = AccentColor -- ^ Contains information about supported accent color for user/chat name, background of empty chat photo, replies to messages and link previews
    { AccentColor -> Maybe Int
_id                          :: Maybe Int   -- ^ Accent color identifier
    , AccentColor -> Maybe Int
built_in_accent_color_id     :: Maybe Int   -- ^ Identifier of a built-in color to use in places, where only one color is needed; 0-6
    , AccentColor -> Maybe [Int]
light_theme_colors           :: Maybe [Int] -- ^ The list of 1-3 colors in RGB format, describing the accent color, as expected to be shown in light themes
    , AccentColor -> Maybe [Int]
dark_theme_colors            :: Maybe [Int] -- ^ The list of 1-3 colors in RGB format, describing the accent color, as expected to be shown in dark themes
    , AccentColor -> Maybe Int
min_channel_chat_boost_level :: Maybe Int   -- ^ The minimum chat boost level required to use the color in a channel chat
    }
  deriving (AccentColor -> AccentColor -> Bool
(AccentColor -> AccentColor -> Bool)
-> (AccentColor -> AccentColor -> Bool) -> Eq AccentColor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AccentColor -> AccentColor -> Bool
== :: AccentColor -> AccentColor -> Bool
$c/= :: AccentColor -> AccentColor -> Bool
/= :: AccentColor -> AccentColor -> Bool
Eq, Int -> AccentColor -> ShowS
[AccentColor] -> ShowS
AccentColor -> String
(Int -> AccentColor -> ShowS)
-> (AccentColor -> String)
-> ([AccentColor] -> ShowS)
-> Show AccentColor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AccentColor -> ShowS
showsPrec :: Int -> AccentColor -> ShowS
$cshow :: AccentColor -> String
show :: AccentColor -> String
$cshowList :: [AccentColor] -> ShowS
showList :: [AccentColor] -> ShowS
Show)

instance I.ShortShow AccentColor where
  shortShow :: AccentColor -> String
shortShow AccentColor
    { _id :: AccentColor -> Maybe Int
_id                          = Maybe Int
_id_
    , built_in_accent_color_id :: AccentColor -> Maybe Int
built_in_accent_color_id     = Maybe Int
built_in_accent_color_id_
    , light_theme_colors :: AccentColor -> Maybe [Int]
light_theme_colors           = Maybe [Int]
light_theme_colors_
    , dark_theme_colors :: AccentColor -> Maybe [Int]
dark_theme_colors            = Maybe [Int]
dark_theme_colors_
    , min_channel_chat_boost_level :: AccentColor -> Maybe Int
min_channel_chat_boost_level = Maybe Int
min_channel_chat_boost_level_
    }
      = String
"AccentColor"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_id"                          String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
        , String
"built_in_accent_color_id"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
built_in_accent_color_id_
        , String
"light_theme_colors"           String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
light_theme_colors_
        , String
"dark_theme_colors"            String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
dark_theme_colors_
        , String
"min_channel_chat_boost_level" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
min_channel_chat_boost_level_
        ]

instance AT.FromJSON AccentColor where
  parseJSON :: Value -> Parser AccentColor
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
"accentColor" -> Value -> Parser AccentColor
parseAccentColor Value
v
      String
_             -> Parser AccentColor
forall a. Monoid a => a
mempty
    
    where
      parseAccentColor :: A.Value -> AT.Parser AccentColor
      parseAccentColor :: Value -> Parser AccentColor
parseAccentColor = String
-> (Object -> Parser AccentColor) -> Value -> Parser AccentColor
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AccentColor" ((Object -> Parser AccentColor) -> Value -> Parser AccentColor)
-> (Object -> Parser AccentColor) -> Value -> Parser AccentColor
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
_id_                          <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"id"
        Maybe Int
built_in_accent_color_id_     <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"built_in_accent_color_id"
        Maybe [Int]
light_theme_colors_           <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"light_theme_colors"
        Maybe [Int]
dark_theme_colors_            <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"dark_theme_colors"
        Maybe Int
min_channel_chat_boost_level_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"min_channel_chat_boost_level"
        AccentColor -> Parser AccentColor
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AccentColor -> Parser AccentColor)
-> AccentColor -> Parser AccentColor
forall a b. (a -> b) -> a -> b
$ AccentColor
          { _id :: Maybe Int
_id                          = Maybe Int
_id_
          , built_in_accent_color_id :: Maybe Int
built_in_accent_color_id     = Maybe Int
built_in_accent_color_id_
          , light_theme_colors :: Maybe [Int]
light_theme_colors           = Maybe [Int]
light_theme_colors_
          , dark_theme_colors :: Maybe [Int]
dark_theme_colors            = Maybe [Int]
dark_theme_colors_
          , min_channel_chat_boost_level :: Maybe Int
min_channel_chat_boost_level = Maybe Int
min_channel_chat_boost_level_
          }
  parseJSON Value
_ = Parser AccentColor
forall a. Monoid a => a
mempty