module TD.Data.ChatFolderInviteLinkInfo
  (ChatFolderInviteLinkInfo(..)) 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.ChatFolderInfo as ChatFolderInfo

data ChatFolderInviteLinkInfo
  = ChatFolderInviteLinkInfo -- ^ Contains information about an invite link to a chat folder
    { ChatFolderInviteLinkInfo -> Maybe ChatFolderInfo
chat_folder_info :: Maybe ChatFolderInfo.ChatFolderInfo -- ^ Basic information about the chat folder; chat folder identifier will be 0 if the user didn't have the chat folder yet
    , ChatFolderInviteLinkInfo -> Maybe [Int]
missing_chat_ids :: Maybe [Int]                         -- ^ Identifiers of the chats from the link, which aren't added to the folder yet
    , ChatFolderInviteLinkInfo -> Maybe [Int]
added_chat_ids   :: Maybe [Int]                         -- ^ Identifiers of the chats from the link, which are added to the folder already
    }
  deriving (ChatFolderInviteLinkInfo -> ChatFolderInviteLinkInfo -> Bool
(ChatFolderInviteLinkInfo -> ChatFolderInviteLinkInfo -> Bool)
-> (ChatFolderInviteLinkInfo -> ChatFolderInviteLinkInfo -> Bool)
-> Eq ChatFolderInviteLinkInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatFolderInviteLinkInfo -> ChatFolderInviteLinkInfo -> Bool
== :: ChatFolderInviteLinkInfo -> ChatFolderInviteLinkInfo -> Bool
$c/= :: ChatFolderInviteLinkInfo -> ChatFolderInviteLinkInfo -> Bool
/= :: ChatFolderInviteLinkInfo -> ChatFolderInviteLinkInfo -> Bool
Eq, Int -> ChatFolderInviteLinkInfo -> ShowS
[ChatFolderInviteLinkInfo] -> ShowS
ChatFolderInviteLinkInfo -> String
(Int -> ChatFolderInviteLinkInfo -> ShowS)
-> (ChatFolderInviteLinkInfo -> String)
-> ([ChatFolderInviteLinkInfo] -> ShowS)
-> Show ChatFolderInviteLinkInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatFolderInviteLinkInfo -> ShowS
showsPrec :: Int -> ChatFolderInviteLinkInfo -> ShowS
$cshow :: ChatFolderInviteLinkInfo -> String
show :: ChatFolderInviteLinkInfo -> String
$cshowList :: [ChatFolderInviteLinkInfo] -> ShowS
showList :: [ChatFolderInviteLinkInfo] -> ShowS
Show)

instance I.ShortShow ChatFolderInviteLinkInfo where
  shortShow :: ChatFolderInviteLinkInfo -> String
shortShow ChatFolderInviteLinkInfo
    { chat_folder_info :: ChatFolderInviteLinkInfo -> Maybe ChatFolderInfo
chat_folder_info = Maybe ChatFolderInfo
chat_folder_info_
    , missing_chat_ids :: ChatFolderInviteLinkInfo -> Maybe [Int]
missing_chat_ids = Maybe [Int]
missing_chat_ids_
    , added_chat_ids :: ChatFolderInviteLinkInfo -> Maybe [Int]
added_chat_ids   = Maybe [Int]
added_chat_ids_
    }
      = String
"ChatFolderInviteLinkInfo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"chat_folder_info" String -> Maybe ChatFolderInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatFolderInfo
chat_folder_info_
        , String
"missing_chat_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
missing_chat_ids_
        , String
"added_chat_ids"   String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
added_chat_ids_
        ]

instance AT.FromJSON ChatFolderInviteLinkInfo where
  parseJSON :: Value -> Parser ChatFolderInviteLinkInfo
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
"chatFolderInviteLinkInfo" -> Value -> Parser ChatFolderInviteLinkInfo
parseChatFolderInviteLinkInfo Value
v
      String
_                          -> Parser ChatFolderInviteLinkInfo
forall a. Monoid a => a
mempty
    
    where
      parseChatFolderInviteLinkInfo :: A.Value -> AT.Parser ChatFolderInviteLinkInfo
      parseChatFolderInviteLinkInfo :: Value -> Parser ChatFolderInviteLinkInfo
parseChatFolderInviteLinkInfo = String
-> (Object -> Parser ChatFolderInviteLinkInfo)
-> Value
-> Parser ChatFolderInviteLinkInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatFolderInviteLinkInfo" ((Object -> Parser ChatFolderInviteLinkInfo)
 -> Value -> Parser ChatFolderInviteLinkInfo)
-> (Object -> Parser ChatFolderInviteLinkInfo)
-> Value
-> Parser ChatFolderInviteLinkInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe ChatFolderInfo
chat_folder_info_ <- Object
o Object -> Key -> Parser (Maybe ChatFolderInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chat_folder_info"
        Maybe [Int]
missing_chat_ids_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"missing_chat_ids"
        Maybe [Int]
added_chat_ids_   <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"added_chat_ids"
        ChatFolderInviteLinkInfo -> Parser ChatFolderInviteLinkInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatFolderInviteLinkInfo -> Parser ChatFolderInviteLinkInfo)
-> ChatFolderInviteLinkInfo -> Parser ChatFolderInviteLinkInfo
forall a b. (a -> b) -> a -> b
$ ChatFolderInviteLinkInfo
          { chat_folder_info :: Maybe ChatFolderInfo
chat_folder_info = Maybe ChatFolderInfo
chat_folder_info_
          , missing_chat_ids :: Maybe [Int]
missing_chat_ids = Maybe [Int]
missing_chat_ids_
          , added_chat_ids :: Maybe [Int]
added_chat_ids   = Maybe [Int]
added_chat_ids_
          }
  parseJSON Value
_ = Parser ChatFolderInviteLinkInfo
forall a. Monoid a => a
mempty