module TD.Data.GiftChatTheme
  (GiftChatTheme(..)) 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.UpgradedGift as UpgradedGift
import qualified TD.Data.ThemeSettings as ThemeSettings

data GiftChatTheme
  = GiftChatTheme -- ^ Describes a chat theme based on an upgraded gift
    { GiftChatTheme -> Maybe UpgradedGift
gift           :: Maybe UpgradedGift.UpgradedGift   -- ^ The gift
    , GiftChatTheme -> Maybe ThemeSettings
light_settings :: Maybe ThemeSettings.ThemeSettings -- ^ Theme settings for a light chat theme
    , GiftChatTheme -> Maybe ThemeSettings
dark_settings  :: Maybe ThemeSettings.ThemeSettings -- ^ Theme settings for a dark chat theme
    }
  deriving (GiftChatTheme -> GiftChatTheme -> Bool
(GiftChatTheme -> GiftChatTheme -> Bool)
-> (GiftChatTheme -> GiftChatTheme -> Bool) -> Eq GiftChatTheme
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiftChatTheme -> GiftChatTheme -> Bool
== :: GiftChatTheme -> GiftChatTheme -> Bool
$c/= :: GiftChatTheme -> GiftChatTheme -> Bool
/= :: GiftChatTheme -> GiftChatTheme -> Bool
Eq, Int -> GiftChatTheme -> ShowS
[GiftChatTheme] -> ShowS
GiftChatTheme -> String
(Int -> GiftChatTheme -> ShowS)
-> (GiftChatTheme -> String)
-> ([GiftChatTheme] -> ShowS)
-> Show GiftChatTheme
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiftChatTheme -> ShowS
showsPrec :: Int -> GiftChatTheme -> ShowS
$cshow :: GiftChatTheme -> String
show :: GiftChatTheme -> String
$cshowList :: [GiftChatTheme] -> ShowS
showList :: [GiftChatTheme] -> ShowS
Show)

instance I.ShortShow GiftChatTheme where
  shortShow :: GiftChatTheme -> String
shortShow GiftChatTheme
    { gift :: GiftChatTheme -> Maybe UpgradedGift
gift           = Maybe UpgradedGift
gift_
    , light_settings :: GiftChatTheme -> Maybe ThemeSettings
light_settings = Maybe ThemeSettings
light_settings_
    , dark_settings :: GiftChatTheme -> Maybe ThemeSettings
dark_settings  = Maybe ThemeSettings
dark_settings_
    }
      = String
"GiftChatTheme"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"gift"           String -> Maybe UpgradedGift -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGift
gift_
        , 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 GiftChatTheme where
  parseJSON :: Value -> Parser GiftChatTheme
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
"giftChatTheme" -> Value -> Parser GiftChatTheme
parseGiftChatTheme Value
v
      String
_               -> Parser GiftChatTheme
forall a. Monoid a => a
mempty
    
    where
      parseGiftChatTheme :: A.Value -> AT.Parser GiftChatTheme
      parseGiftChatTheme :: Value -> Parser GiftChatTheme
parseGiftChatTheme = String
-> (Object -> Parser GiftChatTheme)
-> Value
-> Parser GiftChatTheme
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiftChatTheme" ((Object -> Parser GiftChatTheme) -> Value -> Parser GiftChatTheme)
-> (Object -> Parser GiftChatTheme)
-> Value
-> Parser GiftChatTheme
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe UpgradedGift
gift_           <- Object
o Object -> Key -> Parser (Maybe UpgradedGift)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"gift"
        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"
        GiftChatTheme -> Parser GiftChatTheme
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiftChatTheme -> Parser GiftChatTheme)
-> GiftChatTheme -> Parser GiftChatTheme
forall a b. (a -> b) -> a -> b
$ GiftChatTheme
          { gift :: Maybe UpgradedGift
gift           = Maybe UpgradedGift
gift_
          , light_settings :: Maybe ThemeSettings
light_settings = Maybe ThemeSettings
light_settings_
          , dark_settings :: Maybe ThemeSettings
dark_settings  = Maybe ThemeSettings
dark_settings_
          }
  parseJSON Value
_ = Parser GiftChatTheme
forall a. Monoid a => a
mempty