module TD.Data.CanSendGiftResult
  (CanSendGiftResult(..)) 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

-- | Describes whether a gift can be sent now by the current user
data CanSendGiftResult
  = CanSendGiftResultOk -- ^ The gift can be sent now by the current user
  | CanSendGiftResultFail -- ^ The gift can't be sent now by the current user
    { CanSendGiftResult -> Maybe FormattedText
reason :: Maybe FormattedText.FormattedText -- ^ Reason to be shown to the user
    }
  deriving (CanSendGiftResult -> CanSendGiftResult -> Bool
(CanSendGiftResult -> CanSendGiftResult -> Bool)
-> (CanSendGiftResult -> CanSendGiftResult -> Bool)
-> Eq CanSendGiftResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CanSendGiftResult -> CanSendGiftResult -> Bool
== :: CanSendGiftResult -> CanSendGiftResult -> Bool
$c/= :: CanSendGiftResult -> CanSendGiftResult -> Bool
/= :: CanSendGiftResult -> CanSendGiftResult -> Bool
Eq, Int -> CanSendGiftResult -> ShowS
[CanSendGiftResult] -> ShowS
CanSendGiftResult -> String
(Int -> CanSendGiftResult -> ShowS)
-> (CanSendGiftResult -> String)
-> ([CanSendGiftResult] -> ShowS)
-> Show CanSendGiftResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CanSendGiftResult -> ShowS
showsPrec :: Int -> CanSendGiftResult -> ShowS
$cshow :: CanSendGiftResult -> String
show :: CanSendGiftResult -> String
$cshowList :: [CanSendGiftResult] -> ShowS
showList :: [CanSendGiftResult] -> ShowS
Show)

instance I.ShortShow CanSendGiftResult where
  shortShow :: CanSendGiftResult -> String
shortShow CanSendGiftResult
CanSendGiftResultOk
      = String
"CanSendGiftResultOk"
  shortShow CanSendGiftResultFail
    { reason :: CanSendGiftResult -> Maybe FormattedText
reason = Maybe FormattedText
reason_
    }
      = String
"CanSendGiftResultFail"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"reason" String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
reason_
        ]

instance AT.FromJSON CanSendGiftResult where
  parseJSON :: Value -> Parser CanSendGiftResult
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
"canSendGiftResultOk"   -> CanSendGiftResult -> Parser CanSendGiftResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CanSendGiftResult
CanSendGiftResultOk
      String
"canSendGiftResultFail" -> Value -> Parser CanSendGiftResult
parseCanSendGiftResultFail Value
v
      String
_                       -> Parser CanSendGiftResult
forall a. Monoid a => a
mempty
    
    where
      parseCanSendGiftResultFail :: A.Value -> AT.Parser CanSendGiftResult
      parseCanSendGiftResultFail :: Value -> Parser CanSendGiftResult
parseCanSendGiftResultFail = String
-> (Object -> Parser CanSendGiftResult)
-> Value
-> Parser CanSendGiftResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CanSendGiftResultFail" ((Object -> Parser CanSendGiftResult)
 -> Value -> Parser CanSendGiftResult)
-> (Object -> Parser CanSendGiftResult)
-> Value
-> Parser CanSendGiftResult
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe FormattedText
reason_ <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"reason"
        CanSendGiftResult -> Parser CanSendGiftResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CanSendGiftResult -> Parser CanSendGiftResult)
-> CanSendGiftResult -> Parser CanSendGiftResult
forall a b. (a -> b) -> a -> b
$ CanSendGiftResultFail
          { reason :: Maybe FormattedText
reason = Maybe FormattedText
reason_
          }
  parseJSON Value
_ = Parser CanSendGiftResult
forall a. Monoid a => a
mempty