module TD.Data.ChatInviteLinkSubscriptionInfo
  (ChatInviteLinkSubscriptionInfo(..)) 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.StarSubscriptionPricing as StarSubscriptionPricing

data ChatInviteLinkSubscriptionInfo
  = ChatInviteLinkSubscriptionInfo -- ^ Contains information about subscription plan that must be paid by the user to use a chat invite link
    { ChatInviteLinkSubscriptionInfo -> Maybe StarSubscriptionPricing
pricing   :: Maybe StarSubscriptionPricing.StarSubscriptionPricing -- ^ Information about subscription plan that must be paid by the user to use the link
    , ChatInviteLinkSubscriptionInfo -> Maybe Bool
can_reuse :: Maybe Bool                                            -- ^ True, if the user has already paid for the subscription and can use joinChatByInviteLink to join the subscribed chat again
    , ChatInviteLinkSubscriptionInfo -> Maybe Int
form_id   :: Maybe Int                                             -- ^ Identifier of the payment form to use for subscription payment; 0 if the subscription can't be paid
    }
  deriving (ChatInviteLinkSubscriptionInfo
-> ChatInviteLinkSubscriptionInfo -> Bool
(ChatInviteLinkSubscriptionInfo
 -> ChatInviteLinkSubscriptionInfo -> Bool)
-> (ChatInviteLinkSubscriptionInfo
    -> ChatInviteLinkSubscriptionInfo -> Bool)
-> Eq ChatInviteLinkSubscriptionInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatInviteLinkSubscriptionInfo
-> ChatInviteLinkSubscriptionInfo -> Bool
== :: ChatInviteLinkSubscriptionInfo
-> ChatInviteLinkSubscriptionInfo -> Bool
$c/= :: ChatInviteLinkSubscriptionInfo
-> ChatInviteLinkSubscriptionInfo -> Bool
/= :: ChatInviteLinkSubscriptionInfo
-> ChatInviteLinkSubscriptionInfo -> Bool
Eq, Int -> ChatInviteLinkSubscriptionInfo -> ShowS
[ChatInviteLinkSubscriptionInfo] -> ShowS
ChatInviteLinkSubscriptionInfo -> String
(Int -> ChatInviteLinkSubscriptionInfo -> ShowS)
-> (ChatInviteLinkSubscriptionInfo -> String)
-> ([ChatInviteLinkSubscriptionInfo] -> ShowS)
-> Show ChatInviteLinkSubscriptionInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatInviteLinkSubscriptionInfo -> ShowS
showsPrec :: Int -> ChatInviteLinkSubscriptionInfo -> ShowS
$cshow :: ChatInviteLinkSubscriptionInfo -> String
show :: ChatInviteLinkSubscriptionInfo -> String
$cshowList :: [ChatInviteLinkSubscriptionInfo] -> ShowS
showList :: [ChatInviteLinkSubscriptionInfo] -> ShowS
Show)

instance I.ShortShow ChatInviteLinkSubscriptionInfo where
  shortShow :: ChatInviteLinkSubscriptionInfo -> String
shortShow ChatInviteLinkSubscriptionInfo
    { pricing :: ChatInviteLinkSubscriptionInfo -> Maybe StarSubscriptionPricing
pricing   = Maybe StarSubscriptionPricing
pricing_
    , can_reuse :: ChatInviteLinkSubscriptionInfo -> Maybe Bool
can_reuse = Maybe Bool
can_reuse_
    , form_id :: ChatInviteLinkSubscriptionInfo -> Maybe Int
form_id   = Maybe Int
form_id_
    }
      = String
"ChatInviteLinkSubscriptionInfo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"pricing"   String -> Maybe StarSubscriptionPricing -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StarSubscriptionPricing
pricing_
        , String
"can_reuse" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_reuse_
        , String
"form_id"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
form_id_
        ]

instance AT.FromJSON ChatInviteLinkSubscriptionInfo where
  parseJSON :: Value -> Parser ChatInviteLinkSubscriptionInfo
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
"chatInviteLinkSubscriptionInfo" -> Value -> Parser ChatInviteLinkSubscriptionInfo
parseChatInviteLinkSubscriptionInfo Value
v
      String
_                                -> Parser ChatInviteLinkSubscriptionInfo
forall a. Monoid a => a
mempty
    
    where
      parseChatInviteLinkSubscriptionInfo :: A.Value -> AT.Parser ChatInviteLinkSubscriptionInfo
      parseChatInviteLinkSubscriptionInfo :: Value -> Parser ChatInviteLinkSubscriptionInfo
parseChatInviteLinkSubscriptionInfo = String
-> (Object -> Parser ChatInviteLinkSubscriptionInfo)
-> Value
-> Parser ChatInviteLinkSubscriptionInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatInviteLinkSubscriptionInfo" ((Object -> Parser ChatInviteLinkSubscriptionInfo)
 -> Value -> Parser ChatInviteLinkSubscriptionInfo)
-> (Object -> Parser ChatInviteLinkSubscriptionInfo)
-> Value
-> Parser ChatInviteLinkSubscriptionInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe StarSubscriptionPricing
pricing_   <- Object
o Object -> Key -> Parser (Maybe StarSubscriptionPricing)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"pricing"
        Maybe Bool
can_reuse_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"can_reuse"
        Maybe Int
form_id_   <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"form_id"
        ChatInviteLinkSubscriptionInfo
-> Parser ChatInviteLinkSubscriptionInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatInviteLinkSubscriptionInfo
 -> Parser ChatInviteLinkSubscriptionInfo)
-> ChatInviteLinkSubscriptionInfo
-> Parser ChatInviteLinkSubscriptionInfo
forall a b. (a -> b) -> a -> b
$ ChatInviteLinkSubscriptionInfo
          { pricing :: Maybe StarSubscriptionPricing
pricing   = Maybe StarSubscriptionPricing
pricing_
          , can_reuse :: Maybe Bool
can_reuse = Maybe Bool
can_reuse_
          , form_id :: Maybe Int
form_id   = Maybe Int
form_id_
          }
  parseJSON Value
_ = Parser ChatInviteLinkSubscriptionInfo
forall a. Monoid a => a
mempty