module TD.Data.UpgradedGiftValueInfo
  (UpgradedGiftValueInfo(..)) where

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

data UpgradedGiftValueInfo
  = UpgradedGiftValueInfo -- ^ Contains information about value of an upgraded gift
    { UpgradedGiftValueInfo -> Maybe Text
currency                   :: Maybe T.Text -- ^ ISO 4217 currency code of the currency in which the prices are represented
    , UpgradedGiftValueInfo -> Maybe Int
value                      :: Maybe Int    -- ^ Estimated value of the gift; in the smallest units of the currency
    , UpgradedGiftValueInfo -> Maybe Bool
is_value_average           :: Maybe Bool   -- ^ True, if the value is calculated as average value of similar sold gifts. Otherwise, it is based on the sale price of the gift
    , UpgradedGiftValueInfo -> Maybe Int
initial_sale_date          :: Maybe Int    -- ^ Point in time (Unix timestamp) when the corresponding regular gift was originally purchased
    , UpgradedGiftValueInfo -> Maybe Int
initial_sale_star_count    :: Maybe Int    -- ^ Amount of Telegram Stars that were paid for the gift
    , UpgradedGiftValueInfo -> Maybe Int
initial_sale_price         :: Maybe Int    -- ^ Initial price of the gift; in the smallest units of the currency
    , UpgradedGiftValueInfo -> Maybe Int
last_sale_date             :: Maybe Int    -- ^ Point in time (Unix timestamp) when the upgraded gift was purchased last time; 0 if never
    , UpgradedGiftValueInfo -> Maybe Int
last_sale_price            :: Maybe Int    -- ^ Last purchase price of the gift; in the smallest units of the currency; 0 if the gift has never been resold
    , UpgradedGiftValueInfo -> Maybe Bool
is_last_sale_on_fragment   :: Maybe Bool   -- ^ True, if the last sale was completed on Fragment
    , UpgradedGiftValueInfo -> Maybe Int
minimum_price              :: Maybe Int    -- ^ The current minimum price of gifts upgraded from the same gift; in the smallest units of the currency; 0 if there are no such gifts
    , UpgradedGiftValueInfo -> Maybe Int
average_sale_price         :: Maybe Int    -- ^ The average sale price in the last month of gifts upgraded from the same gift; in the smallest units of the currency; 0 if there were no such sales
    , UpgradedGiftValueInfo -> Maybe Int
telegram_listed_gift_count :: Maybe Int    -- ^ Number of gifts upgraded from the same gift being resold on Telegram
    , UpgradedGiftValueInfo -> Maybe Int
fragment_listed_gift_count :: Maybe Int    -- ^ Number of gifts upgraded from the same gift being resold on Fragment
    , UpgradedGiftValueInfo -> Maybe Text
fragment_url               :: Maybe T.Text -- ^ The HTTPS link to the Fragment for the gift; may be empty if there are no such gifts being sold on Fragment
    }
  deriving (UpgradedGiftValueInfo -> UpgradedGiftValueInfo -> Bool
(UpgradedGiftValueInfo -> UpgradedGiftValueInfo -> Bool)
-> (UpgradedGiftValueInfo -> UpgradedGiftValueInfo -> Bool)
-> Eq UpgradedGiftValueInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UpgradedGiftValueInfo -> UpgradedGiftValueInfo -> Bool
== :: UpgradedGiftValueInfo -> UpgradedGiftValueInfo -> Bool
$c/= :: UpgradedGiftValueInfo -> UpgradedGiftValueInfo -> Bool
/= :: UpgradedGiftValueInfo -> UpgradedGiftValueInfo -> Bool
Eq, Int -> UpgradedGiftValueInfo -> ShowS
[UpgradedGiftValueInfo] -> ShowS
UpgradedGiftValueInfo -> String
(Int -> UpgradedGiftValueInfo -> ShowS)
-> (UpgradedGiftValueInfo -> String)
-> ([UpgradedGiftValueInfo] -> ShowS)
-> Show UpgradedGiftValueInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UpgradedGiftValueInfo -> ShowS
showsPrec :: Int -> UpgradedGiftValueInfo -> ShowS
$cshow :: UpgradedGiftValueInfo -> String
show :: UpgradedGiftValueInfo -> String
$cshowList :: [UpgradedGiftValueInfo] -> ShowS
showList :: [UpgradedGiftValueInfo] -> ShowS
Show)

instance I.ShortShow UpgradedGiftValueInfo where
  shortShow :: UpgradedGiftValueInfo -> String
shortShow UpgradedGiftValueInfo
    { currency :: UpgradedGiftValueInfo -> Maybe Text
currency                   = Maybe Text
currency_
    , value :: UpgradedGiftValueInfo -> Maybe Int
value                      = Maybe Int
value_
    , is_value_average :: UpgradedGiftValueInfo -> Maybe Bool
is_value_average           = Maybe Bool
is_value_average_
    , initial_sale_date :: UpgradedGiftValueInfo -> Maybe Int
initial_sale_date          = Maybe Int
initial_sale_date_
    , initial_sale_star_count :: UpgradedGiftValueInfo -> Maybe Int
initial_sale_star_count    = Maybe Int
initial_sale_star_count_
    , initial_sale_price :: UpgradedGiftValueInfo -> Maybe Int
initial_sale_price         = Maybe Int
initial_sale_price_
    , last_sale_date :: UpgradedGiftValueInfo -> Maybe Int
last_sale_date             = Maybe Int
last_sale_date_
    , last_sale_price :: UpgradedGiftValueInfo -> Maybe Int
last_sale_price            = Maybe Int
last_sale_price_
    , is_last_sale_on_fragment :: UpgradedGiftValueInfo -> Maybe Bool
is_last_sale_on_fragment   = Maybe Bool
is_last_sale_on_fragment_
    , minimum_price :: UpgradedGiftValueInfo -> Maybe Int
minimum_price              = Maybe Int
minimum_price_
    , average_sale_price :: UpgradedGiftValueInfo -> Maybe Int
average_sale_price         = Maybe Int
average_sale_price_
    , telegram_listed_gift_count :: UpgradedGiftValueInfo -> Maybe Int
telegram_listed_gift_count = Maybe Int
telegram_listed_gift_count_
    , fragment_listed_gift_count :: UpgradedGiftValueInfo -> Maybe Int
fragment_listed_gift_count = Maybe Int
fragment_listed_gift_count_
    , fragment_url :: UpgradedGiftValueInfo -> Maybe Text
fragment_url               = Maybe Text
fragment_url_
    }
      = String
"UpgradedGiftValueInfo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"currency"                   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
currency_
        , String
"value"                      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
value_
        , String
"is_value_average"           String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_value_average_
        , String
"initial_sale_date"          String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
initial_sale_date_
        , String
"initial_sale_star_count"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
initial_sale_star_count_
        , String
"initial_sale_price"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
initial_sale_price_
        , String
"last_sale_date"             String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
last_sale_date_
        , String
"last_sale_price"            String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
last_sale_price_
        , String
"is_last_sale_on_fragment"   String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_last_sale_on_fragment_
        , String
"minimum_price"              String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
minimum_price_
        , String
"average_sale_price"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
average_sale_price_
        , String
"telegram_listed_gift_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
telegram_listed_gift_count_
        , String
"fragment_listed_gift_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
fragment_listed_gift_count_
        , String
"fragment_url"               String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
fragment_url_
        ]

instance AT.FromJSON UpgradedGiftValueInfo where
  parseJSON :: Value -> Parser UpgradedGiftValueInfo
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
"upgradedGiftValueInfo" -> Value -> Parser UpgradedGiftValueInfo
parseUpgradedGiftValueInfo Value
v
      String
_                       -> Parser UpgradedGiftValueInfo
forall a. Monoid a => a
mempty
    
    where
      parseUpgradedGiftValueInfo :: A.Value -> AT.Parser UpgradedGiftValueInfo
      parseUpgradedGiftValueInfo :: Value -> Parser UpgradedGiftValueInfo
parseUpgradedGiftValueInfo = String
-> (Object -> Parser UpgradedGiftValueInfo)
-> Value
-> Parser UpgradedGiftValueInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UpgradedGiftValueInfo" ((Object -> Parser UpgradedGiftValueInfo)
 -> Value -> Parser UpgradedGiftValueInfo)
-> (Object -> Parser UpgradedGiftValueInfo)
-> Value
-> Parser UpgradedGiftValueInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
currency_                   <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"currency"
        Maybe Int
value_                      <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"value"
        Maybe Bool
is_value_average_           <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_value_average"
        Maybe Int
initial_sale_date_          <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"initial_sale_date"
        Maybe Int
initial_sale_star_count_    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"initial_sale_star_count"
        Maybe Int
initial_sale_price_         <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"initial_sale_price"
        Maybe Int
last_sale_date_             <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"last_sale_date"
        Maybe Int
last_sale_price_            <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"last_sale_price"
        Maybe Bool
is_last_sale_on_fragment_   <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_last_sale_on_fragment"
        Maybe Int
minimum_price_              <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"minimum_price"
        Maybe Int
average_sale_price_         <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"average_sale_price"
        Maybe Int
telegram_listed_gift_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"telegram_listed_gift_count"
        Maybe Int
fragment_listed_gift_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"fragment_listed_gift_count"
        Maybe Text
fragment_url_               <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"fragment_url"
        UpgradedGiftValueInfo -> Parser UpgradedGiftValueInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UpgradedGiftValueInfo -> Parser UpgradedGiftValueInfo)
-> UpgradedGiftValueInfo -> Parser UpgradedGiftValueInfo
forall a b. (a -> b) -> a -> b
$ UpgradedGiftValueInfo
          { currency :: Maybe Text
currency                   = Maybe Text
currency_
          , value :: Maybe Int
value                      = Maybe Int
value_
          , is_value_average :: Maybe Bool
is_value_average           = Maybe Bool
is_value_average_
          , initial_sale_date :: Maybe Int
initial_sale_date          = Maybe Int
initial_sale_date_
          , initial_sale_star_count :: Maybe Int
initial_sale_star_count    = Maybe Int
initial_sale_star_count_
          , initial_sale_price :: Maybe Int
initial_sale_price         = Maybe Int
initial_sale_price_
          , last_sale_date :: Maybe Int
last_sale_date             = Maybe Int
last_sale_date_
          , last_sale_price :: Maybe Int
last_sale_price            = Maybe Int
last_sale_price_
          , is_last_sale_on_fragment :: Maybe Bool
is_last_sale_on_fragment   = Maybe Bool
is_last_sale_on_fragment_
          , minimum_price :: Maybe Int
minimum_price              = Maybe Int
minimum_price_
          , average_sale_price :: Maybe Int
average_sale_price         = Maybe Int
average_sale_price_
          , telegram_listed_gift_count :: Maybe Int
telegram_listed_gift_count = Maybe Int
telegram_listed_gift_count_
          , fragment_listed_gift_count :: Maybe Int
fragment_listed_gift_count = Maybe Int
fragment_listed_gift_count_
          , fragment_url :: Maybe Text
fragment_url               = Maybe Text
fragment_url_
          }
  parseJSON Value
_ = Parser UpgradedGiftValueInfo
forall a. Monoid a => a
mempty