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

data ChatInviteLink
  = ChatInviteLink -- ^ Contains a chat invite link
    { ChatInviteLink -> Maybe Text
invite_link                :: Maybe T.Text                                          -- ^ Chat invite link
    , ChatInviteLink -> Maybe Text
name                       :: Maybe T.Text                                          -- ^ Name of the link
    , ChatInviteLink -> Maybe Int
creator_user_id            :: Maybe Int                                             -- ^ User identifier of an administrator created the link
    , ChatInviteLink -> Maybe Int
date                       :: Maybe Int                                             -- ^ Point in time (Unix timestamp) when the link was created
    , ChatInviteLink -> Maybe Int
edit_date                  :: Maybe Int                                             -- ^ Point in time (Unix timestamp) when the link was last edited; 0 if never or unknown
    , ChatInviteLink -> Maybe Int
expiration_date            :: Maybe Int                                             -- ^ Point in time (Unix timestamp) when the link will expire; 0 if never
    , ChatInviteLink -> Maybe StarSubscriptionPricing
subscription_pricing       :: Maybe StarSubscriptionPricing.StarSubscriptionPricing -- ^ Information about subscription plan that is applied to the users joining the chat by the link; may be null if the link doesn't require subscription
    , ChatInviteLink -> Maybe Int
member_limit               :: Maybe Int                                             -- ^ The maximum number of members, which can join the chat using the link simultaneously; 0 if not limited. Always 0 if the link requires approval
    , ChatInviteLink -> Maybe Int
member_count               :: Maybe Int                                             -- ^ Number of chat members, which joined the chat using the link
    , ChatInviteLink -> Maybe Int
expired_member_count       :: Maybe Int                                             -- ^ Number of chat members, which joined the chat using the link, but have already left because of expired subscription; for subscription links only
    , ChatInviteLink -> Maybe Int
pending_join_request_count :: Maybe Int                                             -- ^ Number of pending join requests created using this link
    , ChatInviteLink -> Maybe Bool
creates_join_request       :: Maybe Bool                                            -- ^ True, if the link only creates join request. If true, total number of joining members will be unlimited
    , ChatInviteLink -> Maybe Bool
is_primary                 :: Maybe Bool                                            -- ^ True, if the link is primary. Primary invite link can't have name, expiration date, or usage limit. Primary link can create join requests only if this is set up using toggleSupergroupJoinByRequest. There is exactly one primary invite link for each administrator with can_invite_users right at a given time
    , ChatInviteLink -> Maybe Bool
is_revoked                 :: Maybe Bool                                            -- ^ True, if the link was revoked
    }
  deriving (ChatInviteLink -> ChatInviteLink -> Bool
(ChatInviteLink -> ChatInviteLink -> Bool)
-> (ChatInviteLink -> ChatInviteLink -> Bool) -> Eq ChatInviteLink
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatInviteLink -> ChatInviteLink -> Bool
== :: ChatInviteLink -> ChatInviteLink -> Bool
$c/= :: ChatInviteLink -> ChatInviteLink -> Bool
/= :: ChatInviteLink -> ChatInviteLink -> Bool
Eq, Int -> ChatInviteLink -> ShowS
[ChatInviteLink] -> ShowS
ChatInviteLink -> String
(Int -> ChatInviteLink -> ShowS)
-> (ChatInviteLink -> String)
-> ([ChatInviteLink] -> ShowS)
-> Show ChatInviteLink
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatInviteLink -> ShowS
showsPrec :: Int -> ChatInviteLink -> ShowS
$cshow :: ChatInviteLink -> String
show :: ChatInviteLink -> String
$cshowList :: [ChatInviteLink] -> ShowS
showList :: [ChatInviteLink] -> ShowS
Show)

instance I.ShortShow ChatInviteLink where
  shortShow :: ChatInviteLink -> String
shortShow ChatInviteLink
    { invite_link :: ChatInviteLink -> Maybe Text
invite_link                = Maybe Text
invite_link_
    , name :: ChatInviteLink -> Maybe Text
name                       = Maybe Text
name_
    , creator_user_id :: ChatInviteLink -> Maybe Int
creator_user_id            = Maybe Int
creator_user_id_
    , date :: ChatInviteLink -> Maybe Int
date                       = Maybe Int
date_
    , edit_date :: ChatInviteLink -> Maybe Int
edit_date                  = Maybe Int
edit_date_
    , expiration_date :: ChatInviteLink -> Maybe Int
expiration_date            = Maybe Int
expiration_date_
    , subscription_pricing :: ChatInviteLink -> Maybe StarSubscriptionPricing
subscription_pricing       = Maybe StarSubscriptionPricing
subscription_pricing_
    , member_limit :: ChatInviteLink -> Maybe Int
member_limit               = Maybe Int
member_limit_
    , member_count :: ChatInviteLink -> Maybe Int
member_count               = Maybe Int
member_count_
    , expired_member_count :: ChatInviteLink -> Maybe Int
expired_member_count       = Maybe Int
expired_member_count_
    , pending_join_request_count :: ChatInviteLink -> Maybe Int
pending_join_request_count = Maybe Int
pending_join_request_count_
    , creates_join_request :: ChatInviteLink -> Maybe Bool
creates_join_request       = Maybe Bool
creates_join_request_
    , is_primary :: ChatInviteLink -> Maybe Bool
is_primary                 = Maybe Bool
is_primary_
    , is_revoked :: ChatInviteLink -> Maybe Bool
is_revoked                 = Maybe Bool
is_revoked_
    }
      = String
"ChatInviteLink"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"invite_link"                String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
invite_link_
        , String
"name"                       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
        , String
"creator_user_id"            String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
creator_user_id_
        , String
"date"                       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
        , String
"edit_date"                  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
edit_date_
        , String
"expiration_date"            String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expiration_date_
        , String
"subscription_pricing"       String -> Maybe StarSubscriptionPricing -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StarSubscriptionPricing
subscription_pricing_
        , String
"member_limit"               String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
member_limit_
        , String
"member_count"               String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
member_count_
        , String
"expired_member_count"       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expired_member_count_
        , String
"pending_join_request_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
pending_join_request_count_
        , String
"creates_join_request"       String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
creates_join_request_
        , String
"is_primary"                 String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_primary_
        , String
"is_revoked"                 String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_revoked_
        ]

instance AT.FromJSON ChatInviteLink where
  parseJSON :: Value -> Parser ChatInviteLink
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
"chatInviteLink" -> Value -> Parser ChatInviteLink
parseChatInviteLink Value
v
      String
_                -> Parser ChatInviteLink
forall a. Monoid a => a
mempty
    
    where
      parseChatInviteLink :: A.Value -> AT.Parser ChatInviteLink
      parseChatInviteLink :: Value -> Parser ChatInviteLink
parseChatInviteLink = String
-> (Object -> Parser ChatInviteLink)
-> Value
-> Parser ChatInviteLink
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatInviteLink" ((Object -> Parser ChatInviteLink)
 -> Value -> Parser ChatInviteLink)
-> (Object -> Parser ChatInviteLink)
-> Value
-> Parser ChatInviteLink
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
invite_link_                <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"invite_link"
        Maybe Text
name_                       <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"name"
        Maybe Int
creator_user_id_            <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"creator_user_id"
        Maybe Int
date_                       <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"date"
        Maybe Int
edit_date_                  <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"edit_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"
        Maybe StarSubscriptionPricing
subscription_pricing_       <- Object
o Object -> Key -> Parser (Maybe StarSubscriptionPricing)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"subscription_pricing"
        Maybe Int
member_limit_               <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"member_limit"
        Maybe Int
member_count_               <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"member_count"
        Maybe Int
expired_member_count_       <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"expired_member_count"
        Maybe Int
pending_join_request_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"pending_join_request_count"
        Maybe Bool
creates_join_request_       <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"creates_join_request"
        Maybe Bool
is_primary_                 <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_primary"
        Maybe Bool
is_revoked_                 <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_revoked"
        ChatInviteLink -> Parser ChatInviteLink
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatInviteLink -> Parser ChatInviteLink)
-> ChatInviteLink -> Parser ChatInviteLink
forall a b. (a -> b) -> a -> b
$ ChatInviteLink
          { invite_link :: Maybe Text
invite_link                = Maybe Text
invite_link_
          , name :: Maybe Text
name                       = Maybe Text
name_
          , creator_user_id :: Maybe Int
creator_user_id            = Maybe Int
creator_user_id_
          , date :: Maybe Int
date                       = Maybe Int
date_
          , edit_date :: Maybe Int
edit_date                  = Maybe Int
edit_date_
          , expiration_date :: Maybe Int
expiration_date            = Maybe Int
expiration_date_
          , subscription_pricing :: Maybe StarSubscriptionPricing
subscription_pricing       = Maybe StarSubscriptionPricing
subscription_pricing_
          , member_limit :: Maybe Int
member_limit               = Maybe Int
member_limit_
          , member_count :: Maybe Int
member_count               = Maybe Int
member_count_
          , expired_member_count :: Maybe Int
expired_member_count       = Maybe Int
expired_member_count_
          , pending_join_request_count :: Maybe Int
pending_join_request_count = Maybe Int
pending_join_request_count_
          , creates_join_request :: Maybe Bool
creates_join_request       = Maybe Bool
creates_join_request_
          , is_primary :: Maybe Bool
is_primary                 = Maybe Bool
is_primary_
          , is_revoked :: Maybe Bool
is_revoked                 = Maybe Bool
is_revoked_
          }
  parseJSON Value
_ = Parser ChatInviteLink
forall a. Monoid a => a
mempty