module TD.Data.ChatRevenueTransactionType
  (ChatRevenueTransactionType(..)) 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.RevenueWithdrawalState as RevenueWithdrawalState

-- | Describes type of transaction for revenue earned from sponsored messages in a chat
data ChatRevenueTransactionType
  = ChatRevenueTransactionTypeUnsupported -- ^ Describes an unsupported transaction
  | ChatRevenueTransactionTypeSponsoredMessageEarnings -- ^ Describes earnings from sponsored messages in a chat in some time frame
    { ChatRevenueTransactionType -> Maybe Int
start_date :: Maybe Int -- ^ Point in time (Unix timestamp) when the earnings started
    , ChatRevenueTransactionType -> Maybe Int
end_date   :: Maybe Int -- ^ Point in time (Unix timestamp) when the earnings ended
    }
  | ChatRevenueTransactionTypeSuggestedPostEarnings -- ^ Describes earnings from a published suggested post
    { ChatRevenueTransactionType -> Maybe Int
user_id :: Maybe Int -- ^ Identifier of the user that paid for the suggested post
    }
  | ChatRevenueTransactionTypeFragmentWithdrawal -- ^ Describes a withdrawal of earnings through Fragment
    { ChatRevenueTransactionType -> Maybe Int
withdrawal_date :: Maybe Int                                           -- ^ Point in time (Unix timestamp) when the earnings withdrawal started
    , ChatRevenueTransactionType -> Maybe RevenueWithdrawalState
state           :: Maybe RevenueWithdrawalState.RevenueWithdrawalState -- ^ State of the withdrawal
    }
  | ChatRevenueTransactionTypeFragmentRefund -- ^ Describes a refund for failed withdrawal of earnings through Fragment
    { ChatRevenueTransactionType -> Maybe Int
refund_date :: Maybe Int -- ^ Point in time (Unix timestamp) when the transaction was refunded
    }
  deriving (ChatRevenueTransactionType -> ChatRevenueTransactionType -> Bool
(ChatRevenueTransactionType -> ChatRevenueTransactionType -> Bool)
-> (ChatRevenueTransactionType
    -> ChatRevenueTransactionType -> Bool)
-> Eq ChatRevenueTransactionType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatRevenueTransactionType -> ChatRevenueTransactionType -> Bool
== :: ChatRevenueTransactionType -> ChatRevenueTransactionType -> Bool
$c/= :: ChatRevenueTransactionType -> ChatRevenueTransactionType -> Bool
/= :: ChatRevenueTransactionType -> ChatRevenueTransactionType -> Bool
Eq, Int -> ChatRevenueTransactionType -> ShowS
[ChatRevenueTransactionType] -> ShowS
ChatRevenueTransactionType -> String
(Int -> ChatRevenueTransactionType -> ShowS)
-> (ChatRevenueTransactionType -> String)
-> ([ChatRevenueTransactionType] -> ShowS)
-> Show ChatRevenueTransactionType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatRevenueTransactionType -> ShowS
showsPrec :: Int -> ChatRevenueTransactionType -> ShowS
$cshow :: ChatRevenueTransactionType -> String
show :: ChatRevenueTransactionType -> String
$cshowList :: [ChatRevenueTransactionType] -> ShowS
showList :: [ChatRevenueTransactionType] -> ShowS
Show)

instance I.ShortShow ChatRevenueTransactionType where
  shortShow :: ChatRevenueTransactionType -> String
shortShow ChatRevenueTransactionType
ChatRevenueTransactionTypeUnsupported
      = String
"ChatRevenueTransactionTypeUnsupported"
  shortShow ChatRevenueTransactionTypeSponsoredMessageEarnings
    { start_date :: ChatRevenueTransactionType -> Maybe Int
start_date = Maybe Int
start_date_
    , end_date :: ChatRevenueTransactionType -> Maybe Int
end_date   = Maybe Int
end_date_
    }
      = String
"ChatRevenueTransactionTypeSponsoredMessageEarnings"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"start_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
start_date_
        , String
"end_date"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
end_date_
        ]
  shortShow ChatRevenueTransactionTypeSuggestedPostEarnings
    { user_id :: ChatRevenueTransactionType -> Maybe Int
user_id = Maybe Int
user_id_
    }
      = String
"ChatRevenueTransactionTypeSuggestedPostEarnings"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
        ]
  shortShow ChatRevenueTransactionTypeFragmentWithdrawal
    { withdrawal_date :: ChatRevenueTransactionType -> Maybe Int
withdrawal_date = Maybe Int
withdrawal_date_
    , state :: ChatRevenueTransactionType -> Maybe RevenueWithdrawalState
state           = Maybe RevenueWithdrawalState
state_
    }
      = String
"ChatRevenueTransactionTypeFragmentWithdrawal"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"withdrawal_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
withdrawal_date_
        , String
"state"           String -> Maybe RevenueWithdrawalState -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RevenueWithdrawalState
state_
        ]
  shortShow ChatRevenueTransactionTypeFragmentRefund
    { refund_date :: ChatRevenueTransactionType -> Maybe Int
refund_date = Maybe Int
refund_date_
    }
      = String
"ChatRevenueTransactionTypeFragmentRefund"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"refund_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
refund_date_
        ]

instance AT.FromJSON ChatRevenueTransactionType where
  parseJSON :: Value -> Parser ChatRevenueTransactionType
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
"chatRevenueTransactionTypeUnsupported"              -> ChatRevenueTransactionType -> Parser ChatRevenueTransactionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatRevenueTransactionType
ChatRevenueTransactionTypeUnsupported
      String
"chatRevenueTransactionTypeSponsoredMessageEarnings" -> Value -> Parser ChatRevenueTransactionType
parseChatRevenueTransactionTypeSponsoredMessageEarnings Value
v
      String
"chatRevenueTransactionTypeSuggestedPostEarnings"    -> Value -> Parser ChatRevenueTransactionType
parseChatRevenueTransactionTypeSuggestedPostEarnings Value
v
      String
"chatRevenueTransactionTypeFragmentWithdrawal"       -> Value -> Parser ChatRevenueTransactionType
parseChatRevenueTransactionTypeFragmentWithdrawal Value
v
      String
"chatRevenueTransactionTypeFragmentRefund"           -> Value -> Parser ChatRevenueTransactionType
parseChatRevenueTransactionTypeFragmentRefund Value
v
      String
_                                                    -> Parser ChatRevenueTransactionType
forall a. Monoid a => a
mempty
    
    where
      parseChatRevenueTransactionTypeSponsoredMessageEarnings :: A.Value -> AT.Parser ChatRevenueTransactionType
      parseChatRevenueTransactionTypeSponsoredMessageEarnings :: Value -> Parser ChatRevenueTransactionType
parseChatRevenueTransactionTypeSponsoredMessageEarnings = String
-> (Object -> Parser ChatRevenueTransactionType)
-> Value
-> Parser ChatRevenueTransactionType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatRevenueTransactionTypeSponsoredMessageEarnings" ((Object -> Parser ChatRevenueTransactionType)
 -> Value -> Parser ChatRevenueTransactionType)
-> (Object -> Parser ChatRevenueTransactionType)
-> Value
-> Parser ChatRevenueTransactionType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        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
end_date_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"end_date"
        ChatRevenueTransactionType -> Parser ChatRevenueTransactionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatRevenueTransactionType -> Parser ChatRevenueTransactionType)
-> ChatRevenueTransactionType -> Parser ChatRevenueTransactionType
forall a b. (a -> b) -> a -> b
$ ChatRevenueTransactionTypeSponsoredMessageEarnings
          { start_date :: Maybe Int
start_date = Maybe Int
start_date_
          , end_date :: Maybe Int
end_date   = Maybe Int
end_date_
          }
      parseChatRevenueTransactionTypeSuggestedPostEarnings :: A.Value -> AT.Parser ChatRevenueTransactionType
      parseChatRevenueTransactionTypeSuggestedPostEarnings :: Value -> Parser ChatRevenueTransactionType
parseChatRevenueTransactionTypeSuggestedPostEarnings = String
-> (Object -> Parser ChatRevenueTransactionType)
-> Value
-> Parser ChatRevenueTransactionType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatRevenueTransactionTypeSuggestedPostEarnings" ((Object -> Parser ChatRevenueTransactionType)
 -> Value -> Parser ChatRevenueTransactionType)
-> (Object -> Parser ChatRevenueTransactionType)
-> Value
-> Parser ChatRevenueTransactionType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"user_id"
        ChatRevenueTransactionType -> Parser ChatRevenueTransactionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatRevenueTransactionType -> Parser ChatRevenueTransactionType)
-> ChatRevenueTransactionType -> Parser ChatRevenueTransactionType
forall a b. (a -> b) -> a -> b
$ ChatRevenueTransactionTypeSuggestedPostEarnings
          { user_id :: Maybe Int
user_id = Maybe Int
user_id_
          }
      parseChatRevenueTransactionTypeFragmentWithdrawal :: A.Value -> AT.Parser ChatRevenueTransactionType
      parseChatRevenueTransactionTypeFragmentWithdrawal :: Value -> Parser ChatRevenueTransactionType
parseChatRevenueTransactionTypeFragmentWithdrawal = String
-> (Object -> Parser ChatRevenueTransactionType)
-> Value
-> Parser ChatRevenueTransactionType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatRevenueTransactionTypeFragmentWithdrawal" ((Object -> Parser ChatRevenueTransactionType)
 -> Value -> Parser ChatRevenueTransactionType)
-> (Object -> Parser ChatRevenueTransactionType)
-> Value
-> Parser ChatRevenueTransactionType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
withdrawal_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"withdrawal_date"
        Maybe RevenueWithdrawalState
state_           <- Object
o Object -> Key -> Parser (Maybe RevenueWithdrawalState)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"state"
        ChatRevenueTransactionType -> Parser ChatRevenueTransactionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatRevenueTransactionType -> Parser ChatRevenueTransactionType)
-> ChatRevenueTransactionType -> Parser ChatRevenueTransactionType
forall a b. (a -> b) -> a -> b
$ ChatRevenueTransactionTypeFragmentWithdrawal
          { withdrawal_date :: Maybe Int
withdrawal_date = Maybe Int
withdrawal_date_
          , state :: Maybe RevenueWithdrawalState
state           = Maybe RevenueWithdrawalState
state_
          }
      parseChatRevenueTransactionTypeFragmentRefund :: A.Value -> AT.Parser ChatRevenueTransactionType
      parseChatRevenueTransactionTypeFragmentRefund :: Value -> Parser ChatRevenueTransactionType
parseChatRevenueTransactionTypeFragmentRefund = String
-> (Object -> Parser ChatRevenueTransactionType)
-> Value
-> Parser ChatRevenueTransactionType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatRevenueTransactionTypeFragmentRefund" ((Object -> Parser ChatRevenueTransactionType)
 -> Value -> Parser ChatRevenueTransactionType)
-> (Object -> Parser ChatRevenueTransactionType)
-> Value
-> Parser ChatRevenueTransactionType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
refund_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"refund_date"
        ChatRevenueTransactionType -> Parser ChatRevenueTransactionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatRevenueTransactionType -> Parser ChatRevenueTransactionType)
-> ChatRevenueTransactionType -> Parser ChatRevenueTransactionType
forall a b. (a -> b) -> a -> b
$ ChatRevenueTransactionTypeFragmentRefund
          { refund_date :: Maybe Int
refund_date = Maybe Int
refund_date_
          }
  parseJSON Value
_ = Parser ChatRevenueTransactionType
forall a. Monoid a => a
mempty