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 Data.Text as T
import qualified TD.Data.ChatFolderIcon as ChatFolderIcon

data ChatFolderInfo
  = ChatFolderInfo -- ^ Contains basic information about a chat folder
    { ChatFolderInfo -> Maybe Int
_id                 :: Maybe Int                           -- ^ Unique chat folder identifier
    , ChatFolderInfo -> Maybe Text
title               :: Maybe T.Text                        -- ^ The title of the folder; 1-12 characters without line feeds
    , ChatFolderInfo -> Maybe ChatFolderIcon
icon                :: Maybe ChatFolderIcon.ChatFolderIcon -- ^ The chosen or default icon for the chat folder
    , ChatFolderInfo -> Maybe Int
color_id            :: Maybe Int                           -- ^ The identifier of the chosen color for the chat folder icon; from -1 to 6. If -1, then color is disabled
    , ChatFolderInfo -> Maybe Bool
is_shareable        :: Maybe Bool                          -- ^ True, if at least one link has been created for the folder
    , ChatFolderInfo -> Maybe Bool
has_my_invite_links :: Maybe Bool                          -- ^ True, if the chat folder has invite links created by the current user
    }
  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_
    , title :: ChatFolderInfo -> Maybe Text
title               = Maybe Text
title_
    , 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
"title"               String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , 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 Text
title_               <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        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_
          , title :: Maybe Text
title               = Maybe Text
title_
          , 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