module TD.Query.ReportChat
  (ReportChat(..)
  , defaultReportChat
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.ByteString as BS
import qualified Data.Text as T

-- | Reports a chat to the Telegram moderators. A chat can be reported only from the chat action bar, or if chat.can_be_reported. Returns 'TD.Data.ReportChatResult.ReportChatResult'
data ReportChat
  = ReportChat
    { ReportChat -> Maybe Int
chat_id     :: Maybe Int           -- ^ Chat identifier
    , ReportChat -> Maybe ByteString
option_id   :: Maybe BS.ByteString -- ^ Option identifier chosen by the user; leave empty for the initial request
    , ReportChat -> Maybe [Int]
message_ids :: Maybe [Int]         -- ^ Identifiers of reported messages. Use messageProperties.can_report_chat to check whether the message can be reported
    , ReportChat -> Maybe Text
text        :: Maybe T.Text        -- ^ Additional report details if asked by the server; 0-1024 characters; leave empty for the initial request
    }
  deriving (ReportChat -> ReportChat -> Bool
(ReportChat -> ReportChat -> Bool)
-> (ReportChat -> ReportChat -> Bool) -> Eq ReportChat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReportChat -> ReportChat -> Bool
== :: ReportChat -> ReportChat -> Bool
$c/= :: ReportChat -> ReportChat -> Bool
/= :: ReportChat -> ReportChat -> Bool
Eq, Int -> ReportChat -> ShowS
[ReportChat] -> ShowS
ReportChat -> String
(Int -> ReportChat -> ShowS)
-> (ReportChat -> String)
-> ([ReportChat] -> ShowS)
-> Show ReportChat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReportChat -> ShowS
showsPrec :: Int -> ReportChat -> ShowS
$cshow :: ReportChat -> String
show :: ReportChat -> String
$cshowList :: [ReportChat] -> ShowS
showList :: [ReportChat] -> ShowS
Show)

instance I.ShortShow ReportChat where
  shortShow :: ReportChat -> String
shortShow
    ReportChat
      { chat_id :: ReportChat -> Maybe Int
chat_id     = Maybe Int
chat_id_
      , option_id :: ReportChat -> Maybe ByteString
option_id   = Maybe ByteString
option_id_
      , message_ids :: ReportChat -> Maybe [Int]
message_ids = Maybe [Int]
message_ids_
      , text :: ReportChat -> Maybe Text
text        = Maybe Text
text_
      }
        = String
"ReportChat"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"chat_id"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"option_id"   String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
option_id_
          , String
"message_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
message_ids_
          , String
"text"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
text_
          ]

instance AT.ToJSON ReportChat where
  toJSON :: ReportChat -> Value
toJSON
    ReportChat
      { chat_id :: ReportChat -> Maybe Int
chat_id     = Maybe Int
chat_id_
      , option_id :: ReportChat -> Maybe ByteString
option_id   = Maybe ByteString
option_id_
      , message_ids :: ReportChat -> Maybe [Int]
message_ids = Maybe [Int]
message_ids_
      , text :: ReportChat -> Maybe Text
text        = Maybe Text
text_
      }
        = [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
"reportChat"
          , Key
"chat_id"     Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
chat_id_
          , Key
"option_id"   Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (ByteString -> Value) -> Maybe ByteString -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Value
I.writeBytes  Maybe ByteString
option_id_
          , Key
"message_ids" Key -> Maybe [Int] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Int]
message_ids_
          , Key
"text"        Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
text_
          ]

defaultReportChat :: ReportChat
defaultReportChat :: ReportChat
defaultReportChat =
  ReportChat
    { chat_id :: Maybe Int
chat_id     = Maybe Int
forall a. Maybe a
Nothing
    , option_id :: Maybe ByteString
option_id   = Maybe ByteString
forall a. Maybe a
Nothing
    , message_ids :: Maybe [Int]
message_ids = Maybe [Int]
forall a. Maybe a
Nothing
    , text :: Maybe Text
text        = Maybe Text
forall a. Maybe a
Nothing
    }