module TD.Data.PollOption
  (PollOption(..)) 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.FormattedText as FormattedText
import {-# SOURCE #-} qualified TD.Data.MessageContent as MessageContent
import qualified TD.Data.MessageSender as MessageSender

data PollOption
  = PollOption -- ^ Describes one answer option of a poll
    { PollOption -> Maybe Text
_id              :: Maybe T.Text                        -- ^ Unique identifier of the option in the poll
    , PollOption -> Maybe FormattedText
text             :: Maybe FormattedText.FormattedText   -- ^ Option text; 1-100 characters; may contain only custom emoji entities
    , PollOption -> Maybe MessageContent
media            :: Maybe MessageContent.MessageContent -- ^ Option media. Currently, can be only of the types messageAnimation, messageLocation, messagePhoto, messageSticker, messageVenue, or messageVideo without caption
    , PollOption -> Maybe Int
voter_count      :: Maybe Int                           -- ^ Number of voters for this option, available only for closed or voted polls, or if the current user is the creator of the poll
    , PollOption -> Maybe Int
vote_percentage  :: Maybe Int                           -- ^ The percentage of votes for this option; 0-100
    , PollOption -> Maybe [MessageSender]
recent_voter_ids :: Maybe [MessageSender.MessageSender] -- ^ Identifiers of recent voters for the option, if the poll is non-anonymous and poll results are available
    , PollOption -> Maybe Bool
is_chosen        :: Maybe Bool                          -- ^ True, if the option was chosen by the user
    , PollOption -> Maybe Bool
is_being_chosen  :: Maybe Bool                          -- ^ True, if the option is being chosen by a pending setPollAnswer request
    , PollOption -> Maybe MessageSender
author           :: Maybe MessageSender.MessageSender   -- ^ Identifier of the user or chat who added the option; may be null if the option existed from creation of the poll
    , PollOption -> Maybe Int
addition_date    :: Maybe Int                           -- ^ Point in time (Unix timestamp) when the option was added; 0 if the option existed from creation of the poll
    }
  deriving (PollOption -> PollOption -> Bool
(PollOption -> PollOption -> Bool)
-> (PollOption -> PollOption -> Bool) -> Eq PollOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PollOption -> PollOption -> Bool
== :: PollOption -> PollOption -> Bool
$c/= :: PollOption -> PollOption -> Bool
/= :: PollOption -> PollOption -> Bool
Eq, Int -> PollOption -> ShowS
[PollOption] -> ShowS
PollOption -> String
(Int -> PollOption -> ShowS)
-> (PollOption -> String)
-> ([PollOption] -> ShowS)
-> Show PollOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PollOption -> ShowS
showsPrec :: Int -> PollOption -> ShowS
$cshow :: PollOption -> String
show :: PollOption -> String
$cshowList :: [PollOption] -> ShowS
showList :: [PollOption] -> ShowS
Show)

instance I.ShortShow PollOption where
  shortShow :: PollOption -> String
shortShow PollOption
    { _id :: PollOption -> Maybe Text
_id              = Maybe Text
_id_
    , text :: PollOption -> Maybe FormattedText
text             = Maybe FormattedText
text_
    , media :: PollOption -> Maybe MessageContent
media            = Maybe MessageContent
media_
    , voter_count :: PollOption -> Maybe Int
voter_count      = Maybe Int
voter_count_
    , vote_percentage :: PollOption -> Maybe Int
vote_percentage  = Maybe Int
vote_percentage_
    , recent_voter_ids :: PollOption -> Maybe [MessageSender]
recent_voter_ids = Maybe [MessageSender]
recent_voter_ids_
    , is_chosen :: PollOption -> Maybe Bool
is_chosen        = Maybe Bool
is_chosen_
    , is_being_chosen :: PollOption -> Maybe Bool
is_being_chosen  = Maybe Bool
is_being_chosen_
    , author :: PollOption -> Maybe MessageSender
author           = Maybe MessageSender
author_
    , addition_date :: PollOption -> Maybe Int
addition_date    = Maybe Int
addition_date_
    }
      = String
"PollOption"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_id"              String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_id_
        , String
"text"             String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
text_
        , String
"media"            String -> Maybe MessageContent -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageContent
media_
        , String
"voter_count"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
voter_count_
        , String
"vote_percentage"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
vote_percentage_
        , String
"recent_voter_ids" String -> Maybe [MessageSender] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [MessageSender]
recent_voter_ids_
        , String
"is_chosen"        String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_chosen_
        , String
"is_being_chosen"  String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_being_chosen_
        , String
"author"           String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
author_
        , String
"addition_date"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
addition_date_
        ]

instance AT.FromJSON PollOption where
  parseJSON :: Value -> Parser PollOption
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
"pollOption" -> Value -> Parser PollOption
parsePollOption Value
v
      String
_            -> Parser PollOption
forall a. Monoid a => a
mempty
    
    where
      parsePollOption :: A.Value -> AT.Parser PollOption
      parsePollOption :: Value -> Parser PollOption
parsePollOption = String
-> (Object -> Parser PollOption) -> Value -> Parser PollOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PollOption" ((Object -> Parser PollOption) -> Value -> Parser PollOption)
-> (Object -> Parser PollOption) -> Value -> Parser PollOption
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
_id_              <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"id"
        Maybe FormattedText
text_             <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe MessageContent
media_            <- Object
o Object -> Key -> Parser (Maybe MessageContent)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"media"
        Maybe Int
voter_count_      <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"voter_count"
        Maybe Int
vote_percentage_  <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"vote_percentage"
        Maybe [MessageSender]
recent_voter_ids_ <- Object
o Object -> Key -> Parser (Maybe [MessageSender])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"recent_voter_ids"
        Maybe Bool
is_chosen_        <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_chosen"
        Maybe Bool
is_being_chosen_  <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_being_chosen"
        Maybe MessageSender
author_           <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"author"
        Maybe Int
addition_date_    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"addition_date"
        PollOption -> Parser PollOption
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PollOption -> Parser PollOption)
-> PollOption -> Parser PollOption
forall a b. (a -> b) -> a -> b
$ PollOption
          { _id :: Maybe Text
_id              = Maybe Text
_id_
          , text :: Maybe FormattedText
text             = Maybe FormattedText
text_
          , media :: Maybe MessageContent
media            = Maybe MessageContent
media_
          , voter_count :: Maybe Int
voter_count      = Maybe Int
voter_count_
          , vote_percentage :: Maybe Int
vote_percentage  = Maybe Int
vote_percentage_
          , recent_voter_ids :: Maybe [MessageSender]
recent_voter_ids = Maybe [MessageSender]
recent_voter_ids_
          , is_chosen :: Maybe Bool
is_chosen        = Maybe Bool
is_chosen_
          , is_being_chosen :: Maybe Bool
is_being_chosen  = Maybe Bool
is_being_chosen_
          , author :: Maybe MessageSender
author           = Maybe MessageSender
author_
          , addition_date :: Maybe Int
addition_date    = Maybe Int
addition_date_
          }
  parseJSON Value
_ = Parser PollOption
forall a. Monoid a => a
mempty