module TD.Data.UserAuctionBid
  (UserAuctionBid(..)) 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.MessageSender as MessageSender

data UserAuctionBid
  = UserAuctionBid -- ^ Describes a bid of the current user in an auction
    { UserAuctionBid -> Maybe Int
star_count          :: Maybe Int                         -- ^ The number of Telegram Stars that were put in the bid
    , UserAuctionBid -> Maybe Int
bid_date            :: Maybe Int                         -- ^ Point in time (Unix timestamp) when the bid was made
    , UserAuctionBid -> Maybe Int
next_bid_star_count :: Maybe Int                         -- ^ The minimum number of Telegram Stars that can be put for the next bid
    , UserAuctionBid -> Maybe MessageSender
owner_id            :: Maybe MessageSender.MessageSender -- ^ Identifier of the user or the chat that will receive the auctioned item. If the auction is opened in context of another user or chat, then a warning is supposed to be shown to the current user
    , UserAuctionBid -> Maybe Bool
was_returned        :: Maybe Bool                        -- ^ True, if the bid was returned to the user, because it was outbid and can't win anymore
    }
  deriving (UserAuctionBid -> UserAuctionBid -> Bool
(UserAuctionBid -> UserAuctionBid -> Bool)
-> (UserAuctionBid -> UserAuctionBid -> Bool) -> Eq UserAuctionBid
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserAuctionBid -> UserAuctionBid -> Bool
== :: UserAuctionBid -> UserAuctionBid -> Bool
$c/= :: UserAuctionBid -> UserAuctionBid -> Bool
/= :: UserAuctionBid -> UserAuctionBid -> Bool
Eq, Int -> UserAuctionBid -> ShowS
[UserAuctionBid] -> ShowS
UserAuctionBid -> String
(Int -> UserAuctionBid -> ShowS)
-> (UserAuctionBid -> String)
-> ([UserAuctionBid] -> ShowS)
-> Show UserAuctionBid
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserAuctionBid -> ShowS
showsPrec :: Int -> UserAuctionBid -> ShowS
$cshow :: UserAuctionBid -> String
show :: UserAuctionBid -> String
$cshowList :: [UserAuctionBid] -> ShowS
showList :: [UserAuctionBid] -> ShowS
Show)

instance I.ShortShow UserAuctionBid where
  shortShow :: UserAuctionBid -> String
shortShow UserAuctionBid
    { star_count :: UserAuctionBid -> Maybe Int
star_count          = Maybe Int
star_count_
    , bid_date :: UserAuctionBid -> Maybe Int
bid_date            = Maybe Int
bid_date_
    , next_bid_star_count :: UserAuctionBid -> Maybe Int
next_bid_star_count = Maybe Int
next_bid_star_count_
    , owner_id :: UserAuctionBid -> Maybe MessageSender
owner_id            = Maybe MessageSender
owner_id_
    , was_returned :: UserAuctionBid -> Maybe Bool
was_returned        = Maybe Bool
was_returned_
    }
      = String
"UserAuctionBid"
        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
"bid_date"            String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bid_date_
        , String
"next_bid_star_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
next_bid_star_count_
        , String
"owner_id"            String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
owner_id_
        , String
"was_returned"        String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
was_returned_
        ]

instance AT.FromJSON UserAuctionBid where
  parseJSON :: Value -> Parser UserAuctionBid
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
"userAuctionBid" -> Value -> Parser UserAuctionBid
parseUserAuctionBid Value
v
      String
_                -> Parser UserAuctionBid
forall a. Monoid a => a
mempty
    
    where
      parseUserAuctionBid :: A.Value -> AT.Parser UserAuctionBid
      parseUserAuctionBid :: Value -> Parser UserAuctionBid
parseUserAuctionBid = String
-> (Object -> Parser UserAuctionBid)
-> Value
-> Parser UserAuctionBid
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserAuctionBid" ((Object -> Parser UserAuctionBid)
 -> Value -> Parser UserAuctionBid)
-> (Object -> Parser UserAuctionBid)
-> Value
-> Parser UserAuctionBid
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
bid_date_            <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"bid_date"
        Maybe Int
next_bid_star_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"next_bid_star_count"
        Maybe MessageSender
owner_id_            <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"owner_id"
        Maybe Bool
was_returned_        <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"was_returned"
        UserAuctionBid -> Parser UserAuctionBid
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserAuctionBid -> Parser UserAuctionBid)
-> UserAuctionBid -> Parser UserAuctionBid
forall a b. (a -> b) -> a -> b
$ UserAuctionBid
          { star_count :: Maybe Int
star_count          = Maybe Int
star_count_
          , bid_date :: Maybe Int
bid_date            = Maybe Int
bid_date_
          , next_bid_star_count :: Maybe Int
next_bid_star_count = Maybe Int
next_bid_star_count_
          , owner_id :: Maybe MessageSender
owner_id            = Maybe MessageSender
owner_id_
          , was_returned :: Maybe Bool
was_returned        = Maybe Bool
was_returned_
          }
  parseJSON Value
_ = Parser UserAuctionBid
forall a. Monoid a => a
mempty