module TD.Data.GiftBackground
  (GiftBackground(..)) where

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

data GiftBackground
  = GiftBackground -- ^ Describes background of a gift
    { GiftBackground -> Maybe Int
center_color :: Maybe Int -- ^ Center color in RGB format
    , GiftBackground -> Maybe Int
edge_color   :: Maybe Int -- ^ Edge color in RGB format
    , GiftBackground -> Maybe Int
text_color   :: Maybe Int -- ^ Text color in RGB format
    }
  deriving (GiftBackground -> GiftBackground -> Bool
(GiftBackground -> GiftBackground -> Bool)
-> (GiftBackground -> GiftBackground -> Bool) -> Eq GiftBackground
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiftBackground -> GiftBackground -> Bool
== :: GiftBackground -> GiftBackground -> Bool
$c/= :: GiftBackground -> GiftBackground -> Bool
/= :: GiftBackground -> GiftBackground -> Bool
Eq, Int -> GiftBackground -> ShowS
[GiftBackground] -> ShowS
GiftBackground -> String
(Int -> GiftBackground -> ShowS)
-> (GiftBackground -> String)
-> ([GiftBackground] -> ShowS)
-> Show GiftBackground
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiftBackground -> ShowS
showsPrec :: Int -> GiftBackground -> ShowS
$cshow :: GiftBackground -> String
show :: GiftBackground -> String
$cshowList :: [GiftBackground] -> ShowS
showList :: [GiftBackground] -> ShowS
Show)

instance I.ShortShow GiftBackground where
  shortShow :: GiftBackground -> String
shortShow GiftBackground
    { center_color :: GiftBackground -> Maybe Int
center_color = Maybe Int
center_color_
    , edge_color :: GiftBackground -> Maybe Int
edge_color   = Maybe Int
edge_color_
    , text_color :: GiftBackground -> Maybe Int
text_color   = Maybe Int
text_color_
    }
      = String
"GiftBackground"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"center_color" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
center_color_
        , String
"edge_color"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
edge_color_
        , String
"text_color"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
text_color_
        ]

instance AT.FromJSON GiftBackground where
  parseJSON :: Value -> Parser GiftBackground
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
"giftBackground" -> Value -> Parser GiftBackground
parseGiftBackground Value
v
      String
_                -> Parser GiftBackground
forall a. Monoid a => a
mempty
    
    where
      parseGiftBackground :: A.Value -> AT.Parser GiftBackground
      parseGiftBackground :: Value -> Parser GiftBackground
parseGiftBackground = String
-> (Object -> Parser GiftBackground)
-> Value
-> Parser GiftBackground
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiftBackground" ((Object -> Parser GiftBackground)
 -> Value -> Parser GiftBackground)
-> (Object -> Parser GiftBackground)
-> Value
-> Parser GiftBackground
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
center_color_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"center_color"
        Maybe Int
edge_color_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"edge_color"
        Maybe Int
text_color_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text_color"
        GiftBackground -> Parser GiftBackground
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiftBackground -> Parser GiftBackground)
-> GiftBackground -> Parser GiftBackground
forall a b. (a -> b) -> a -> b
$ GiftBackground
          { center_color :: Maybe Int
center_color = Maybe Int
center_color_
          , edge_color :: Maybe Int
edge_color   = Maybe Int
edge_color_
          , text_color :: Maybe Int
text_color   = Maybe Int
text_color_
          }
  parseJSON Value
_ = Parser GiftBackground
forall a. Monoid a => a
mempty