module TD.Data.ChatActionBar
  (ChatActionBar(..)) 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

-- | Describes actions which must be possible to do through a chat action bar
data ChatActionBar
  = ChatActionBarReportSpam -- ^ The chat can be reported as spam using the method reportChat with an empty option_id and message_ids. If the chat is a private chat with a user with an emoji status, then a notice about emoji status usage must be shown
    { ChatActionBar -> Maybe Bool
can_unarchive :: Maybe Bool -- ^ If true, the chat was automatically archived and can be moved back to the main chat list using addChatToList simultaneously with setting chat notification settings to default using setChatNotificationSettings
    }
  | ChatActionBarInviteMembers -- ^ The chat is a recently created group chat to which new members can be invited
  | ChatActionBarReportAddBlock -- ^ The chat is a private or secret chat, which can be reported using the method reportChat, or the other user can be blocked using the method setMessageSenderBlockList, or the other user can be added to the contact list using the method addContact. If the chat is a private chat with a user with an emoji status, then a notice about emoji status usage must be shown
    { can_unarchive :: Maybe Bool -- ^ If true, the chat was automatically archived and can be moved back to the main chat list using addChatToList simultaneously with setting chat notification settings to default using setChatNotificationSettings
    }
  | ChatActionBarAddContact -- ^ The chat is a private or secret chat and the other user can be added to the contact list using the method addContact
  | ChatActionBarSharePhoneNumber -- ^ The chat is a private or secret chat with a mutual contact and the user's phone number can be shared with the other user using the method sharePhoneNumber
  | ChatActionBarJoinRequest -- ^ The chat is a private chat with an administrator of a chat to which the user sent join request
    { ChatActionBar -> Maybe Text
title        :: Maybe T.Text -- ^ Title of the chat to which the join request was sent
    , ChatActionBar -> Maybe Bool
is_channel   :: Maybe Bool   -- ^ True, if the join request was sent to a channel chat
    , ChatActionBar -> Maybe Int
request_date :: Maybe Int    -- ^ Point in time (Unix timestamp) when the join request was sent
    }
  deriving (ChatActionBar -> ChatActionBar -> Bool
(ChatActionBar -> ChatActionBar -> Bool)
-> (ChatActionBar -> ChatActionBar -> Bool) -> Eq ChatActionBar
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatActionBar -> ChatActionBar -> Bool
== :: ChatActionBar -> ChatActionBar -> Bool
$c/= :: ChatActionBar -> ChatActionBar -> Bool
/= :: ChatActionBar -> ChatActionBar -> Bool
Eq, Int -> ChatActionBar -> ShowS
[ChatActionBar] -> ShowS
ChatActionBar -> String
(Int -> ChatActionBar -> ShowS)
-> (ChatActionBar -> String)
-> ([ChatActionBar] -> ShowS)
-> Show ChatActionBar
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatActionBar -> ShowS
showsPrec :: Int -> ChatActionBar -> ShowS
$cshow :: ChatActionBar -> String
show :: ChatActionBar -> String
$cshowList :: [ChatActionBar] -> ShowS
showList :: [ChatActionBar] -> ShowS
Show)

instance I.ShortShow ChatActionBar where
  shortShow :: ChatActionBar -> String
shortShow ChatActionBarReportSpam
    { can_unarchive :: ChatActionBar -> Maybe Bool
can_unarchive = Maybe Bool
can_unarchive_
    }
      = String
"ChatActionBarReportSpam"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"can_unarchive" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_unarchive_
        ]
  shortShow ChatActionBar
ChatActionBarInviteMembers
      = String
"ChatActionBarInviteMembers"
  shortShow ChatActionBarReportAddBlock
    { can_unarchive :: ChatActionBar -> Maybe Bool
can_unarchive = Maybe Bool
can_unarchive_
    }
      = String
"ChatActionBarReportAddBlock"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"can_unarchive" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_unarchive_
        ]
  shortShow ChatActionBar
ChatActionBarAddContact
      = String
"ChatActionBarAddContact"
  shortShow ChatActionBar
ChatActionBarSharePhoneNumber
      = String
"ChatActionBarSharePhoneNumber"
  shortShow ChatActionBarJoinRequest
    { title :: ChatActionBar -> Maybe Text
title        = Maybe Text
title_
    , is_channel :: ChatActionBar -> Maybe Bool
is_channel   = Maybe Bool
is_channel_
    , request_date :: ChatActionBar -> Maybe Int
request_date = Maybe Int
request_date_
    }
      = String
"ChatActionBarJoinRequest"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"title"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"is_channel"   String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_channel_
        , String
"request_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
request_date_
        ]

instance AT.FromJSON ChatActionBar where
  parseJSON :: Value -> Parser ChatActionBar
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
"chatActionBarReportSpam"       -> Value -> Parser ChatActionBar
parseChatActionBarReportSpam Value
v
      String
"chatActionBarInviteMembers"    -> ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatActionBar
ChatActionBarInviteMembers
      String
"chatActionBarReportAddBlock"   -> Value -> Parser ChatActionBar
parseChatActionBarReportAddBlock Value
v
      String
"chatActionBarAddContact"       -> ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatActionBar
ChatActionBarAddContact
      String
"chatActionBarSharePhoneNumber" -> ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatActionBar
ChatActionBarSharePhoneNumber
      String
"chatActionBarJoinRequest"      -> Value -> Parser ChatActionBar
parseChatActionBarJoinRequest Value
v
      String
_                               -> Parser ChatActionBar
forall a. Monoid a => a
mempty
    
    where
      parseChatActionBarReportSpam :: A.Value -> AT.Parser ChatActionBar
      parseChatActionBarReportSpam :: Value -> Parser ChatActionBar
parseChatActionBarReportSpam = String
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionBarReportSpam" ((Object -> Parser ChatActionBar) -> Value -> Parser ChatActionBar)
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
can_unarchive_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_unarchive"
        ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatActionBar -> Parser ChatActionBar)
-> ChatActionBar -> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ ChatActionBarReportSpam
          { can_unarchive :: Maybe Bool
can_unarchive = Maybe Bool
can_unarchive_
          }
      parseChatActionBarReportAddBlock :: A.Value -> AT.Parser ChatActionBar
      parseChatActionBarReportAddBlock :: Value -> Parser ChatActionBar
parseChatActionBarReportAddBlock = String
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionBarReportAddBlock" ((Object -> Parser ChatActionBar) -> Value -> Parser ChatActionBar)
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
can_unarchive_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_unarchive"
        ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatActionBar -> Parser ChatActionBar)
-> ChatActionBar -> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ ChatActionBarReportAddBlock
          { can_unarchive :: Maybe Bool
can_unarchive = Maybe Bool
can_unarchive_
          }
      parseChatActionBarJoinRequest :: A.Value -> AT.Parser ChatActionBar
      parseChatActionBarJoinRequest :: Value -> Parser ChatActionBar
parseChatActionBarJoinRequest = String
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionBarJoinRequest" ((Object -> Parser ChatActionBar) -> Value -> Parser ChatActionBar)
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
title_        <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        Maybe Bool
is_channel_   <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_channel"
        Maybe Int
request_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"request_date"
        ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatActionBar -> Parser ChatActionBar)
-> ChatActionBar -> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ ChatActionBarJoinRequest
          { title :: Maybe Text
title        = Maybe Text
title_
          , is_channel :: Maybe Bool
is_channel   = Maybe Bool
is_channel_
          , request_date :: Maybe Int
request_date = Maybe Int
request_date_
          }
  parseJSON Value
_ = Parser ChatActionBar
forall a. Monoid a => a
mempty