module TD.Data.RecommendedChatFolders
  (RecommendedChatFolders(..)) 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.RecommendedChatFolder as RecommendedChatFolder

data RecommendedChatFolders
  = RecommendedChatFolders -- ^ Contains a list of recommended chat folders
    { RecommendedChatFolders -> Maybe [RecommendedChatFolder]
chat_folders :: Maybe [RecommendedChatFolder.RecommendedChatFolder] -- ^ List of recommended chat folders
    }
  deriving (RecommendedChatFolders -> RecommendedChatFolders -> Bool
(RecommendedChatFolders -> RecommendedChatFolders -> Bool)
-> (RecommendedChatFolders -> RecommendedChatFolders -> Bool)
-> Eq RecommendedChatFolders
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RecommendedChatFolders -> RecommendedChatFolders -> Bool
== :: RecommendedChatFolders -> RecommendedChatFolders -> Bool
$c/= :: RecommendedChatFolders -> RecommendedChatFolders -> Bool
/= :: RecommendedChatFolders -> RecommendedChatFolders -> Bool
Eq, Int -> RecommendedChatFolders -> ShowS
[RecommendedChatFolders] -> ShowS
RecommendedChatFolders -> String
(Int -> RecommendedChatFolders -> ShowS)
-> (RecommendedChatFolders -> String)
-> ([RecommendedChatFolders] -> ShowS)
-> Show RecommendedChatFolders
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RecommendedChatFolders -> ShowS
showsPrec :: Int -> RecommendedChatFolders -> ShowS
$cshow :: RecommendedChatFolders -> String
show :: RecommendedChatFolders -> String
$cshowList :: [RecommendedChatFolders] -> ShowS
showList :: [RecommendedChatFolders] -> ShowS
Show)

instance I.ShortShow RecommendedChatFolders where
  shortShow :: RecommendedChatFolders -> String
shortShow RecommendedChatFolders
    { chat_folders :: RecommendedChatFolders -> Maybe [RecommendedChatFolder]
chat_folders = Maybe [RecommendedChatFolder]
chat_folders_
    }
      = String
"RecommendedChatFolders"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"chat_folders" String -> Maybe [RecommendedChatFolder] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [RecommendedChatFolder]
chat_folders_
        ]

instance AT.FromJSON RecommendedChatFolders where
  parseJSON :: Value -> Parser RecommendedChatFolders
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
"recommendedChatFolders" -> Value -> Parser RecommendedChatFolders
parseRecommendedChatFolders Value
v
      String
_                        -> Parser RecommendedChatFolders
forall a. Monoid a => a
mempty
    
    where
      parseRecommendedChatFolders :: A.Value -> AT.Parser RecommendedChatFolders
      parseRecommendedChatFolders :: Value -> Parser RecommendedChatFolders
parseRecommendedChatFolders = String
-> (Object -> Parser RecommendedChatFolders)
-> Value
-> Parser RecommendedChatFolders
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RecommendedChatFolders" ((Object -> Parser RecommendedChatFolders)
 -> Value -> Parser RecommendedChatFolders)
-> (Object -> Parser RecommendedChatFolders)
-> Value
-> Parser RecommendedChatFolders
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [RecommendedChatFolder]
chat_folders_ <- Object
o Object -> Key -> Parser (Maybe [RecommendedChatFolder])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chat_folders"
        RecommendedChatFolders -> Parser RecommendedChatFolders
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RecommendedChatFolders -> Parser RecommendedChatFolders)
-> RecommendedChatFolders -> Parser RecommendedChatFolders
forall a b. (a -> b) -> a -> b
$ RecommendedChatFolders
          { chat_folders :: Maybe [RecommendedChatFolder]
chat_folders = Maybe [RecommendedChatFolder]
chat_folders_
          }
  parseJSON Value
_ = Parser RecommendedChatFolders
forall a. Monoid a => a
mempty