module TD.Data.GiftResaleParameters
  (GiftResaleParameters(..)) where

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

data GiftResaleParameters
  = GiftResaleParameters -- ^ Describes parameters of a unique gift available for resale
    { GiftResaleParameters -> Maybe Int
star_count         :: Maybe Int  -- ^ Resale price of the gift in Telegram Stars
    , GiftResaleParameters -> Maybe Int
toncoin_cent_count :: Maybe Int  -- ^ Resale price of the gift in 1/100 of Toncoin
    , GiftResaleParameters -> Maybe Bool
toncoin_only       :: Maybe Bool -- ^ True, if the gift can be bought only using Toncoins
    }
  deriving (GiftResaleParameters -> GiftResaleParameters -> Bool
(GiftResaleParameters -> GiftResaleParameters -> Bool)
-> (GiftResaleParameters -> GiftResaleParameters -> Bool)
-> Eq GiftResaleParameters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiftResaleParameters -> GiftResaleParameters -> Bool
== :: GiftResaleParameters -> GiftResaleParameters -> Bool
$c/= :: GiftResaleParameters -> GiftResaleParameters -> Bool
/= :: GiftResaleParameters -> GiftResaleParameters -> Bool
Eq, Int -> GiftResaleParameters -> ShowS
[GiftResaleParameters] -> ShowS
GiftResaleParameters -> String
(Int -> GiftResaleParameters -> ShowS)
-> (GiftResaleParameters -> String)
-> ([GiftResaleParameters] -> ShowS)
-> Show GiftResaleParameters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiftResaleParameters -> ShowS
showsPrec :: Int -> GiftResaleParameters -> ShowS
$cshow :: GiftResaleParameters -> String
show :: GiftResaleParameters -> String
$cshowList :: [GiftResaleParameters] -> ShowS
showList :: [GiftResaleParameters] -> ShowS
Show)

instance I.ShortShow GiftResaleParameters where
  shortShow :: GiftResaleParameters -> String
shortShow GiftResaleParameters
    { star_count :: GiftResaleParameters -> Maybe Int
star_count         = Maybe Int
star_count_
    , toncoin_cent_count :: GiftResaleParameters -> Maybe Int
toncoin_cent_count = Maybe Int
toncoin_cent_count_
    , toncoin_only :: GiftResaleParameters -> Maybe Bool
toncoin_only       = Maybe Bool
toncoin_only_
    }
      = String
"GiftResaleParameters"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"star_count"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
star_count_
        , String
"toncoin_cent_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
toncoin_cent_count_
        , String
"toncoin_only"       String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
toncoin_only_
        ]

instance AT.FromJSON GiftResaleParameters where
  parseJSON :: Value -> Parser GiftResaleParameters
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
"giftResaleParameters" -> Value -> Parser GiftResaleParameters
parseGiftResaleParameters Value
v
      String
_                      -> Parser GiftResaleParameters
forall a. Monoid a => a
mempty
    
    where
      parseGiftResaleParameters :: A.Value -> AT.Parser GiftResaleParameters
      parseGiftResaleParameters :: Value -> Parser GiftResaleParameters
parseGiftResaleParameters = String
-> (Object -> Parser GiftResaleParameters)
-> Value
-> Parser GiftResaleParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiftResaleParameters" ((Object -> Parser GiftResaleParameters)
 -> Value -> Parser GiftResaleParameters)
-> (Object -> Parser GiftResaleParameters)
-> Value
-> Parser GiftResaleParameters
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
star_count_         <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"star_count"
        Maybe Int
toncoin_cent_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"toncoin_cent_count"
        Maybe Bool
toncoin_only_       <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"toncoin_only"
        GiftResaleParameters -> Parser GiftResaleParameters
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiftResaleParameters -> Parser GiftResaleParameters)
-> GiftResaleParameters -> Parser GiftResaleParameters
forall a b. (a -> b) -> a -> b
$ GiftResaleParameters
          { star_count :: Maybe Int
star_count         = Maybe Int
star_count_
          , toncoin_cent_count :: Maybe Int
toncoin_cent_count = Maybe Int
toncoin_cent_count_
          , toncoin_only :: Maybe Bool
toncoin_only       = Maybe Bool
toncoin_only_
          }
  parseJSON Value
_ = Parser GiftResaleParameters
forall a. Monoid a => a
mempty