module TD.Data.ChatFolderInfo
(ChatFolderInfo(..)) 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.ChatFolderName as ChatFolderName
import qualified TD.Data.ChatFolderIcon as ChatFolderIcon
data ChatFolderInfo
= ChatFolderInfo
{ ChatFolderInfo -> Maybe Int
_id :: Maybe Int
, ChatFolderInfo -> Maybe ChatFolderName
name :: Maybe ChatFolderName.ChatFolderName
, ChatFolderInfo -> Maybe ChatFolderIcon
icon :: Maybe ChatFolderIcon.ChatFolderIcon
, ChatFolderInfo -> Maybe Int
color_id :: Maybe Int
, ChatFolderInfo -> Maybe Bool
is_shareable :: Maybe Bool
, ChatFolderInfo -> Maybe Bool
has_my_invite_links :: Maybe Bool
}
deriving (ChatFolderInfo -> ChatFolderInfo -> Bool
(ChatFolderInfo -> ChatFolderInfo -> Bool)
-> (ChatFolderInfo -> ChatFolderInfo -> Bool) -> Eq ChatFolderInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatFolderInfo -> ChatFolderInfo -> Bool
== :: ChatFolderInfo -> ChatFolderInfo -> Bool
$c/= :: ChatFolderInfo -> ChatFolderInfo -> Bool
/= :: ChatFolderInfo -> ChatFolderInfo -> Bool
Eq, Int -> ChatFolderInfo -> ShowS
[ChatFolderInfo] -> ShowS
ChatFolderInfo -> String
(Int -> ChatFolderInfo -> ShowS)
-> (ChatFolderInfo -> String)
-> ([ChatFolderInfo] -> ShowS)
-> Show ChatFolderInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatFolderInfo -> ShowS
showsPrec :: Int -> ChatFolderInfo -> ShowS
$cshow :: ChatFolderInfo -> String
show :: ChatFolderInfo -> String
$cshowList :: [ChatFolderInfo] -> ShowS
showList :: [ChatFolderInfo] -> ShowS
Show)
instance I.ShortShow ChatFolderInfo where
shortShow :: ChatFolderInfo -> String
shortShow ChatFolderInfo
{ _id :: ChatFolderInfo -> Maybe Int
_id = Maybe Int
_id_
, name :: ChatFolderInfo -> Maybe ChatFolderName
name = Maybe ChatFolderName
name_
, icon :: ChatFolderInfo -> Maybe ChatFolderIcon
icon = Maybe ChatFolderIcon
icon_
, color_id :: ChatFolderInfo -> Maybe Int
color_id = Maybe Int
color_id_
, is_shareable :: ChatFolderInfo -> Maybe Bool
is_shareable = Maybe Bool
is_shareable_
, has_my_invite_links :: ChatFolderInfo -> Maybe Bool
has_my_invite_links = Maybe Bool
has_my_invite_links_
}
= String
"ChatFolderInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"name" String -> Maybe ChatFolderName -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatFolderName
name_
, String
"icon" String -> Maybe ChatFolderIcon -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatFolderIcon
icon_
, String
"color_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
color_id_
, String
"is_shareable" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_shareable_
, String
"has_my_invite_links" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_my_invite_links_
]
instance AT.FromJSON ChatFolderInfo where
parseJSON :: Value -> Parser ChatFolderInfo
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
"chatFolderInfo" -> Value -> Parser ChatFolderInfo
parseChatFolderInfo Value
v
String
_ -> Parser ChatFolderInfo
forall a. Monoid a => a
mempty
where
parseChatFolderInfo :: A.Value -> AT.Parser ChatFolderInfo
parseChatFolderInfo :: Value -> Parser ChatFolderInfo
parseChatFolderInfo = String
-> (Object -> Parser ChatFolderInfo)
-> Value
-> Parser ChatFolderInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatFolderInfo" ((Object -> Parser ChatFolderInfo)
-> Value -> Parser ChatFolderInfo)
-> (Object -> Parser ChatFolderInfo)
-> Value
-> Parser ChatFolderInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe ChatFolderName
name_ <- Object
o Object -> Key -> Parser (Maybe ChatFolderName)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"name"
Maybe ChatFolderIcon
icon_ <- Object
o Object -> Key -> Parser (Maybe ChatFolderIcon)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"icon"
Maybe Int
color_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"color_id"
Maybe Bool
is_shareable_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_shareable"
Maybe Bool
has_my_invite_links_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"has_my_invite_links"
ChatFolderInfo -> Parser ChatFolderInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatFolderInfo -> Parser ChatFolderInfo)
-> ChatFolderInfo -> Parser ChatFolderInfo
forall a b. (a -> b) -> a -> b
$ ChatFolderInfo
{ _id :: Maybe Int
_id = Maybe Int
_id_
, name :: Maybe ChatFolderName
name = Maybe ChatFolderName
name_
, icon :: Maybe ChatFolderIcon
icon = Maybe ChatFolderIcon
icon_
, color_id :: Maybe Int
color_id = Maybe Int
color_id_
, is_shareable :: Maybe Bool
is_shareable = Maybe Bool
is_shareable_
, has_my_invite_links :: Maybe Bool
has_my_invite_links = Maybe Bool
has_my_invite_links_
}
parseJSON Value
_ = Parser ChatFolderInfo
forall a. Monoid a => a
mempty