module TD.Query.SetPollAnswer
  (SetPollAnswer(..)
  , defaultSetPollAnswer
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

-- | Changes the user answer to a poll. A poll in quiz mode can be answered only once. Returns 'TD.Data.Ok.Ok'
data SetPollAnswer
  = SetPollAnswer
    { SetPollAnswer -> Maybe Int
chat_id    :: Maybe Int   -- ^ Identifier of the chat to which the poll belongs
    , SetPollAnswer -> Maybe Int
message_id :: Maybe Int   -- ^ Identifier of the message containing the poll
    , SetPollAnswer -> Maybe [Int]
option_ids :: Maybe [Int] -- ^ 0-based identifiers of answer options, chosen by the user. User can choose more than 1 answer option only is the poll allows multiple answers
    }
  deriving (SetPollAnswer -> SetPollAnswer -> Bool
(SetPollAnswer -> SetPollAnswer -> Bool)
-> (SetPollAnswer -> SetPollAnswer -> Bool) -> Eq SetPollAnswer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetPollAnswer -> SetPollAnswer -> Bool
== :: SetPollAnswer -> SetPollAnswer -> Bool
$c/= :: SetPollAnswer -> SetPollAnswer -> Bool
/= :: SetPollAnswer -> SetPollAnswer -> Bool
Eq, Int -> SetPollAnswer -> ShowS
[SetPollAnswer] -> ShowS
SetPollAnswer -> String
(Int -> SetPollAnswer -> ShowS)
-> (SetPollAnswer -> String)
-> ([SetPollAnswer] -> ShowS)
-> Show SetPollAnswer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetPollAnswer -> ShowS
showsPrec :: Int -> SetPollAnswer -> ShowS
$cshow :: SetPollAnswer -> String
show :: SetPollAnswer -> String
$cshowList :: [SetPollAnswer] -> ShowS
showList :: [SetPollAnswer] -> ShowS
Show)

instance I.ShortShow SetPollAnswer where
  shortShow :: SetPollAnswer -> String
shortShow
    SetPollAnswer
      { chat_id :: SetPollAnswer -> Maybe Int
chat_id    = Maybe Int
chat_id_
      , message_id :: SetPollAnswer -> Maybe Int
message_id = Maybe Int
message_id_
      , option_ids :: SetPollAnswer -> Maybe [Int]
option_ids = Maybe [Int]
option_ids_
      }
        = String
"SetPollAnswer"
          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
"message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
          , String
"option_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
option_ids_
          ]

instance AT.ToJSON SetPollAnswer where
  toJSON :: SetPollAnswer -> Value
toJSON
    SetPollAnswer
      { chat_id :: SetPollAnswer -> Maybe Int
chat_id    = Maybe Int
chat_id_
      , message_id :: SetPollAnswer -> Maybe Int
message_id = Maybe Int
message_id_
      , option_ids :: SetPollAnswer -> Maybe [Int]
option_ids = Maybe [Int]
option_ids_
      }
        = [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
"setPollAnswer"
          , 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
"message_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
message_id_
          , Key
"option_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]
option_ids_
          ]

defaultSetPollAnswer :: SetPollAnswer
defaultSetPollAnswer :: SetPollAnswer
defaultSetPollAnswer =
  SetPollAnswer
    { chat_id :: Maybe Int
chat_id    = Maybe Int
forall a. Maybe a
Nothing
    , message_id :: Maybe Int
message_id = Maybe Int
forall a. Maybe a
Nothing
    , option_ids :: Maybe [Int]
option_ids = Maybe [Int]
forall a. Maybe a
Nothing
    }