module TD.Data.ChatFolderName
  ( ChatFolderName(..)    
  , defaultChatFolderName 
  ) 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.FormattedText as FormattedText

data ChatFolderName
  = ChatFolderName -- ^ Describes name of a chat folder
    { ChatFolderName -> Maybe FormattedText
text                 :: Maybe FormattedText.FormattedText -- ^ The text of the chat folder name; 1-12 characters without line feeds. May contain only CustomEmoji entities
    , ChatFolderName -> Maybe Bool
animate_custom_emoji :: Maybe Bool                        -- ^ True, if custom emoji in the name must be animated
    }
  deriving (ChatFolderName -> ChatFolderName -> Bool
(ChatFolderName -> ChatFolderName -> Bool)
-> (ChatFolderName -> ChatFolderName -> Bool) -> Eq ChatFolderName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatFolderName -> ChatFolderName -> Bool
== :: ChatFolderName -> ChatFolderName -> Bool
$c/= :: ChatFolderName -> ChatFolderName -> Bool
/= :: ChatFolderName -> ChatFolderName -> Bool
Eq, Int -> ChatFolderName -> ShowS
[ChatFolderName] -> ShowS
ChatFolderName -> String
(Int -> ChatFolderName -> ShowS)
-> (ChatFolderName -> String)
-> ([ChatFolderName] -> ShowS)
-> Show ChatFolderName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatFolderName -> ShowS
showsPrec :: Int -> ChatFolderName -> ShowS
$cshow :: ChatFolderName -> String
show :: ChatFolderName -> String
$cshowList :: [ChatFolderName] -> ShowS
showList :: [ChatFolderName] -> ShowS
Show)

instance I.ShortShow ChatFolderName where
  shortShow :: ChatFolderName -> String
shortShow ChatFolderName
    { text :: ChatFolderName -> Maybe FormattedText
text                 = Maybe FormattedText
text_
    , animate_custom_emoji :: ChatFolderName -> Maybe Bool
animate_custom_emoji = Maybe Bool
animate_custom_emoji_
    }
      = String
"ChatFolderName"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"text"                 String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
text_
        , String
"animate_custom_emoji" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
animate_custom_emoji_
        ]

instance AT.FromJSON ChatFolderName where
  parseJSON :: Value -> Parser ChatFolderName
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
"chatFolderName" -> Value -> Parser ChatFolderName
parseChatFolderName Value
v
      String
_                -> Parser ChatFolderName
forall a. Monoid a => a
mempty
    
    where
      parseChatFolderName :: A.Value -> AT.Parser ChatFolderName
      parseChatFolderName :: Value -> Parser ChatFolderName
parseChatFolderName = String
-> (Object -> Parser ChatFolderName)
-> Value
-> Parser ChatFolderName
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatFolderName" ((Object -> Parser ChatFolderName)
 -> Value -> Parser ChatFolderName)
-> (Object -> Parser ChatFolderName)
-> Value
-> Parser ChatFolderName
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe FormattedText
text_                 <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe Bool
animate_custom_emoji_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"animate_custom_emoji"
        ChatFolderName -> Parser ChatFolderName
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatFolderName -> Parser ChatFolderName)
-> ChatFolderName -> Parser ChatFolderName
forall a b. (a -> b) -> a -> b
$ ChatFolderName
          { text :: Maybe FormattedText
text                 = Maybe FormattedText
text_
          , animate_custom_emoji :: Maybe Bool
animate_custom_emoji = Maybe Bool
animate_custom_emoji_
          }
  parseJSON Value
_ = Parser ChatFolderName
forall a. Monoid a => a
mempty

instance AT.ToJSON ChatFolderName where
  toJSON :: ChatFolderName -> Value
toJSON ChatFolderName
    { text :: ChatFolderName -> Maybe FormattedText
text                 = Maybe FormattedText
text_
    , animate_custom_emoji :: ChatFolderName -> Maybe Bool
animate_custom_emoji = Maybe Bool
animate_custom_emoji_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"                Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatFolderName"
        , Key
"text"                 Key -> Maybe FormattedText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FormattedText
text_
        , Key
"animate_custom_emoji" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
animate_custom_emoji_
        ]

defaultChatFolderName :: ChatFolderName
defaultChatFolderName :: ChatFolderName
defaultChatFolderName =
  ChatFolderName
    { text :: Maybe FormattedText
text                 = Maybe FormattedText
forall a. Maybe a
Nothing
    , animate_custom_emoji :: Maybe Bool
animate_custom_emoji = Maybe Bool
forall a. Maybe a
Nothing
    }