module TD.Data.RecommendedChatFolder
  (RecommendedChatFolder(..)) 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.ChatFolder as ChatFolder
import qualified Data.Text as T

data RecommendedChatFolder
  = RecommendedChatFolder -- ^ Describes a recommended chat folder
    { RecommendedChatFolder -> Maybe ChatFolder
folder      :: Maybe ChatFolder.ChatFolder -- ^ The chat folder
    , RecommendedChatFolder -> Maybe Text
description :: Maybe T.Text                -- ^ Chat folder description
    }
  deriving (RecommendedChatFolder -> RecommendedChatFolder -> Bool
(RecommendedChatFolder -> RecommendedChatFolder -> Bool)
-> (RecommendedChatFolder -> RecommendedChatFolder -> Bool)
-> Eq RecommendedChatFolder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RecommendedChatFolder -> RecommendedChatFolder -> Bool
== :: RecommendedChatFolder -> RecommendedChatFolder -> Bool
$c/= :: RecommendedChatFolder -> RecommendedChatFolder -> Bool
/= :: RecommendedChatFolder -> RecommendedChatFolder -> Bool
Eq, Int -> RecommendedChatFolder -> ShowS
[RecommendedChatFolder] -> ShowS
RecommendedChatFolder -> String
(Int -> RecommendedChatFolder -> ShowS)
-> (RecommendedChatFolder -> String)
-> ([RecommendedChatFolder] -> ShowS)
-> Show RecommendedChatFolder
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RecommendedChatFolder -> ShowS
showsPrec :: Int -> RecommendedChatFolder -> ShowS
$cshow :: RecommendedChatFolder -> String
show :: RecommendedChatFolder -> String
$cshowList :: [RecommendedChatFolder] -> ShowS
showList :: [RecommendedChatFolder] -> ShowS
Show)

instance I.ShortShow RecommendedChatFolder where
  shortShow :: RecommendedChatFolder -> String
shortShow RecommendedChatFolder
    { folder :: RecommendedChatFolder -> Maybe ChatFolder
folder      = Maybe ChatFolder
folder_
    , description :: RecommendedChatFolder -> Maybe Text
description = Maybe Text
description_
    }
      = String
"RecommendedChatFolder"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"folder"      String -> Maybe ChatFolder -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatFolder
folder_
        , String
"description" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
description_
        ]

instance AT.FromJSON RecommendedChatFolder where
  parseJSON :: Value -> Parser RecommendedChatFolder
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
"recommendedChatFolder" -> Value -> Parser RecommendedChatFolder
parseRecommendedChatFolder Value
v
      String
_                       -> Parser RecommendedChatFolder
forall a. Monoid a => a
mempty
    
    where
      parseRecommendedChatFolder :: A.Value -> AT.Parser RecommendedChatFolder
      parseRecommendedChatFolder :: Value -> Parser RecommendedChatFolder
parseRecommendedChatFolder = String
-> (Object -> Parser RecommendedChatFolder)
-> Value
-> Parser RecommendedChatFolder
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RecommendedChatFolder" ((Object -> Parser RecommendedChatFolder)
 -> Value -> Parser RecommendedChatFolder)
-> (Object -> Parser RecommendedChatFolder)
-> Value
-> Parser RecommendedChatFolder
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe ChatFolder
folder_      <- Object
o Object -> Key -> Parser (Maybe ChatFolder)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"folder"
        Maybe Text
description_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"description"
        RecommendedChatFolder -> Parser RecommendedChatFolder
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RecommendedChatFolder -> Parser RecommendedChatFolder)
-> RecommendedChatFolder -> Parser RecommendedChatFolder
forall a b. (a -> b) -> a -> b
$ RecommendedChatFolder
          { folder :: Maybe ChatFolder
folder      = Maybe ChatFolder
folder_
          , description :: Maybe Text
description = Maybe Text
description_
          }
  parseJSON Value
_ = Parser RecommendedChatFolder
forall a. Monoid a => a
mempty