module TD.Data.UpgradedGiftOriginalDetails
  (UpgradedGiftOriginalDetails(..)) 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.FormattedText as FormattedText

data UpgradedGiftOriginalDetails
  = UpgradedGiftOriginalDetails -- ^ Describes the original details about the gift
    { UpgradedGiftOriginalDetails -> Maybe Int
sender_user_id   :: Maybe Int                         -- ^ Identifier of the user that sent the gift; 0 if the gift was private
    , UpgradedGiftOriginalDetails -> Maybe Int
receiver_user_id :: Maybe Int                         -- ^ Identifier of the user that received the gift
    , UpgradedGiftOriginalDetails -> Maybe FormattedText
text             :: Maybe FormattedText.FormattedText -- ^ Message added to the gift
    , UpgradedGiftOriginalDetails -> Maybe Int
date             :: Maybe Int                         -- ^ Point in time (Unix timestamp) when the gift was sent
    }
  deriving (UpgradedGiftOriginalDetails -> UpgradedGiftOriginalDetails -> Bool
(UpgradedGiftOriginalDetails
 -> UpgradedGiftOriginalDetails -> Bool)
-> (UpgradedGiftOriginalDetails
    -> UpgradedGiftOriginalDetails -> Bool)
-> Eq UpgradedGiftOriginalDetails
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UpgradedGiftOriginalDetails -> UpgradedGiftOriginalDetails -> Bool
== :: UpgradedGiftOriginalDetails -> UpgradedGiftOriginalDetails -> Bool
$c/= :: UpgradedGiftOriginalDetails -> UpgradedGiftOriginalDetails -> Bool
/= :: UpgradedGiftOriginalDetails -> UpgradedGiftOriginalDetails -> Bool
Eq, Int -> UpgradedGiftOriginalDetails -> ShowS
[UpgradedGiftOriginalDetails] -> ShowS
UpgradedGiftOriginalDetails -> String
(Int -> UpgradedGiftOriginalDetails -> ShowS)
-> (UpgradedGiftOriginalDetails -> String)
-> ([UpgradedGiftOriginalDetails] -> ShowS)
-> Show UpgradedGiftOriginalDetails
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UpgradedGiftOriginalDetails -> ShowS
showsPrec :: Int -> UpgradedGiftOriginalDetails -> ShowS
$cshow :: UpgradedGiftOriginalDetails -> String
show :: UpgradedGiftOriginalDetails -> String
$cshowList :: [UpgradedGiftOriginalDetails] -> ShowS
showList :: [UpgradedGiftOriginalDetails] -> ShowS
Show)

instance I.ShortShow UpgradedGiftOriginalDetails where
  shortShow :: UpgradedGiftOriginalDetails -> String
shortShow UpgradedGiftOriginalDetails
    { sender_user_id :: UpgradedGiftOriginalDetails -> Maybe Int
sender_user_id   = Maybe Int
sender_user_id_
    , receiver_user_id :: UpgradedGiftOriginalDetails -> Maybe Int
receiver_user_id = Maybe Int
receiver_user_id_
    , text :: UpgradedGiftOriginalDetails -> Maybe FormattedText
text             = Maybe FormattedText
text_
    , date :: UpgradedGiftOriginalDetails -> Maybe Int
date             = Maybe Int
date_
    }
      = String
"UpgradedGiftOriginalDetails"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"sender_user_id"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sender_user_id_
        , String
"receiver_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
receiver_user_id_
        , String
"text"             String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
text_
        , String
"date"             String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
        ]

instance AT.FromJSON UpgradedGiftOriginalDetails where
  parseJSON :: Value -> Parser UpgradedGiftOriginalDetails
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
"upgradedGiftOriginalDetails" -> Value -> Parser UpgradedGiftOriginalDetails
parseUpgradedGiftOriginalDetails Value
v
      String
_                             -> Parser UpgradedGiftOriginalDetails
forall a. Monoid a => a
mempty
    
    where
      parseUpgradedGiftOriginalDetails :: A.Value -> AT.Parser UpgradedGiftOriginalDetails
      parseUpgradedGiftOriginalDetails :: Value -> Parser UpgradedGiftOriginalDetails
parseUpgradedGiftOriginalDetails = String
-> (Object -> Parser UpgradedGiftOriginalDetails)
-> Value
-> Parser UpgradedGiftOriginalDetails
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UpgradedGiftOriginalDetails" ((Object -> Parser UpgradedGiftOriginalDetails)
 -> Value -> Parser UpgradedGiftOriginalDetails)
-> (Object -> Parser UpgradedGiftOriginalDetails)
-> Value
-> Parser UpgradedGiftOriginalDetails
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
sender_user_id_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sender_user_id"
        Maybe Int
receiver_user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"receiver_user_id"
        Maybe FormattedText
text_             <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe Int
date_             <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"date"
        UpgradedGiftOriginalDetails -> Parser UpgradedGiftOriginalDetails
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UpgradedGiftOriginalDetails -> Parser UpgradedGiftOriginalDetails)
-> UpgradedGiftOriginalDetails
-> Parser UpgradedGiftOriginalDetails
forall a b. (a -> b) -> a -> b
$ UpgradedGiftOriginalDetails
          { sender_user_id :: Maybe Int
sender_user_id   = Maybe Int
sender_user_id_
          , receiver_user_id :: Maybe Int
receiver_user_id = Maybe Int
receiver_user_id_
          , text :: Maybe FormattedText
text             = Maybe FormattedText
text_
          , date :: Maybe Int
date             = Maybe Int
date_
          }
  parseJSON Value
_ = Parser UpgradedGiftOriginalDetails
forall a. Monoid a => a
mempty