module TD.Data.ChatBoost
  (ChatBoost(..)) 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
import qualified TD.Data.ChatBoostSource as ChatBoostSource

data ChatBoost
  = ChatBoost -- ^ Describes a boost applied to a chat
    { ChatBoost -> Maybe Text
_id             :: Maybe T.Text                          -- ^ Unique identifier of the boost
    , ChatBoost -> Maybe Int
count           :: Maybe Int                             -- ^ The number of identical boosts applied
    , ChatBoost -> Maybe ChatBoostSource
source          :: Maybe ChatBoostSource.ChatBoostSource -- ^ Source of the boost
    , ChatBoost -> Maybe Int
start_date      :: Maybe Int                             -- ^ Point in time (Unix timestamp) when the chat was boosted
    , ChatBoost -> Maybe Int
expiration_date :: Maybe Int                             -- ^ Point in time (Unix timestamp) when the boost will expire
    }
  deriving (ChatBoost -> ChatBoost -> Bool
(ChatBoost -> ChatBoost -> Bool)
-> (ChatBoost -> ChatBoost -> Bool) -> Eq ChatBoost
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatBoost -> ChatBoost -> Bool
== :: ChatBoost -> ChatBoost -> Bool
$c/= :: ChatBoost -> ChatBoost -> Bool
/= :: ChatBoost -> ChatBoost -> Bool
Eq, Int -> ChatBoost -> ShowS
[ChatBoost] -> ShowS
ChatBoost -> String
(Int -> ChatBoost -> ShowS)
-> (ChatBoost -> String)
-> ([ChatBoost] -> ShowS)
-> Show ChatBoost
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatBoost -> ShowS
showsPrec :: Int -> ChatBoost -> ShowS
$cshow :: ChatBoost -> String
show :: ChatBoost -> String
$cshowList :: [ChatBoost] -> ShowS
showList :: [ChatBoost] -> ShowS
Show)

instance I.ShortShow ChatBoost where
  shortShow :: ChatBoost -> String
shortShow ChatBoost
    { _id :: ChatBoost -> Maybe Text
_id             = Maybe Text
_id_
    , count :: ChatBoost -> Maybe Int
count           = Maybe Int
count_
    , source :: ChatBoost -> Maybe ChatBoostSource
source          = Maybe ChatBoostSource
source_
    , start_date :: ChatBoost -> Maybe Int
start_date      = Maybe Int
start_date_
    , expiration_date :: ChatBoost -> Maybe Int
expiration_date = Maybe Int
expiration_date_
    }
      = String
"ChatBoost"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_id"             String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_id_
        , String
"count"           String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
count_
        , String
"source"          String -> Maybe ChatBoostSource -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatBoostSource
source_
        , String
"start_date"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
start_date_
        , String
"expiration_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expiration_date_
        ]

instance AT.FromJSON ChatBoost where
  parseJSON :: Value -> Parser ChatBoost
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
"chatBoost" -> Value -> Parser ChatBoost
parseChatBoost Value
v
      String
_           -> Parser ChatBoost
forall a. Monoid a => a
mempty
    
    where
      parseChatBoost :: A.Value -> AT.Parser ChatBoost
      parseChatBoost :: Value -> Parser ChatBoost
parseChatBoost = String -> (Object -> Parser ChatBoost) -> Value -> Parser ChatBoost
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatBoost" ((Object -> Parser ChatBoost) -> Value -> Parser ChatBoost)
-> (Object -> Parser ChatBoost) -> Value -> Parser ChatBoost
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
_id_             <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"id"
        Maybe Int
count_           <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"count"
        Maybe ChatBoostSource
source_          <- Object
o Object -> Key -> Parser (Maybe ChatBoostSource)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"source"
        Maybe Int
start_date_      <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"start_date"
        Maybe Int
expiration_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"expiration_date"
        ChatBoost -> Parser ChatBoost
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatBoost -> Parser ChatBoost) -> ChatBoost -> Parser ChatBoost
forall a b. (a -> b) -> a -> b
$ ChatBoost
          { _id :: Maybe Text
_id             = Maybe Text
_id_
          , count :: Maybe Int
count           = Maybe Int
count_
          , source :: Maybe ChatBoostSource
source          = Maybe ChatBoostSource
source_
          , start_date :: Maybe Int
start_date      = Maybe Int
start_date_
          , expiration_date :: Maybe Int
expiration_date = Maybe Int
expiration_date_
          }
  parseJSON Value
_ = Parser ChatBoost
forall a. Monoid a => a
mempty