module TD.Data.GiftForResale
  (GiftForResale(..)) 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 Data.Text as T

data GiftForResale
  = GiftForResale -- ^ Describes a gift available for resale
    { GiftForResale -> Maybe UpgradedGift
gift             :: Maybe UpgradedGift.UpgradedGift -- ^ The gift
    , GiftForResale -> Maybe Text
received_gift_id :: Maybe T.Text                    -- ^ Unique identifier of the received gift for the current user; only for the gifts owned by the current user
    }
  deriving (GiftForResale -> GiftForResale -> Bool
(GiftForResale -> GiftForResale -> Bool)
-> (GiftForResale -> GiftForResale -> Bool) -> Eq GiftForResale
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiftForResale -> GiftForResale -> Bool
== :: GiftForResale -> GiftForResale -> Bool
$c/= :: GiftForResale -> GiftForResale -> Bool
/= :: GiftForResale -> GiftForResale -> Bool
Eq, Int -> GiftForResale -> ShowS
[GiftForResale] -> ShowS
GiftForResale -> String
(Int -> GiftForResale -> ShowS)
-> (GiftForResale -> String)
-> ([GiftForResale] -> ShowS)
-> Show GiftForResale
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiftForResale -> ShowS
showsPrec :: Int -> GiftForResale -> ShowS
$cshow :: GiftForResale -> String
show :: GiftForResale -> String
$cshowList :: [GiftForResale] -> ShowS
showList :: [GiftForResale] -> ShowS
Show)

instance I.ShortShow GiftForResale where
  shortShow :: GiftForResale -> String
shortShow GiftForResale
    { gift :: GiftForResale -> Maybe UpgradedGift
gift             = Maybe UpgradedGift
gift_
    , received_gift_id :: GiftForResale -> Maybe Text
received_gift_id = Maybe Text
received_gift_id_
    }
      = String
"GiftForResale"
        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
"received_gift_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
received_gift_id_
        ]

instance AT.FromJSON GiftForResale where
  parseJSON :: Value -> Parser GiftForResale
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
"giftForResale" -> Value -> Parser GiftForResale
parseGiftForResale Value
v
      String
_               -> Parser GiftForResale
forall a. Monoid a => a
mempty
    
    where
      parseGiftForResale :: A.Value -> AT.Parser GiftForResale
      parseGiftForResale :: Value -> Parser GiftForResale
parseGiftForResale = String
-> (Object -> Parser GiftForResale)
-> Value
-> Parser GiftForResale
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiftForResale" ((Object -> Parser GiftForResale) -> Value -> Parser GiftForResale)
-> (Object -> Parser GiftForResale)
-> Value
-> Parser GiftForResale
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 Text
received_gift_id_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"received_gift_id"
        GiftForResale -> Parser GiftForResale
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiftForResale -> Parser GiftForResale)
-> GiftForResale -> Parser GiftForResale
forall a b. (a -> b) -> a -> b
$ GiftForResale
          { gift :: Maybe UpgradedGift
gift             = Maybe UpgradedGift
gift_
          , received_gift_id :: Maybe Text
received_gift_id = Maybe Text
received_gift_id_
          }
  parseJSON Value
_ = Parser GiftForResale
forall a. Monoid a => a
mempty