module TD.Data.PollVoteStatistics
  (PollVoteStatistics(..)) 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.StatisticalGraph as StatisticalGraph

data PollVoteStatistics
  = PollVoteStatistics -- ^ A detailed statistics about poll votes
    { PollVoteStatistics -> Maybe StatisticalGraph
vote_graph :: Maybe StatisticalGraph.StatisticalGraph -- ^ A graph containing distribution of votes in the poll
    }
  deriving (PollVoteStatistics -> PollVoteStatistics -> Bool
(PollVoteStatistics -> PollVoteStatistics -> Bool)
-> (PollVoteStatistics -> PollVoteStatistics -> Bool)
-> Eq PollVoteStatistics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PollVoteStatistics -> PollVoteStatistics -> Bool
== :: PollVoteStatistics -> PollVoteStatistics -> Bool
$c/= :: PollVoteStatistics -> PollVoteStatistics -> Bool
/= :: PollVoteStatistics -> PollVoteStatistics -> Bool
Eq, Int -> PollVoteStatistics -> ShowS
[PollVoteStatistics] -> ShowS
PollVoteStatistics -> String
(Int -> PollVoteStatistics -> ShowS)
-> (PollVoteStatistics -> String)
-> ([PollVoteStatistics] -> ShowS)
-> Show PollVoteStatistics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PollVoteStatistics -> ShowS
showsPrec :: Int -> PollVoteStatistics -> ShowS
$cshow :: PollVoteStatistics -> String
show :: PollVoteStatistics -> String
$cshowList :: [PollVoteStatistics] -> ShowS
showList :: [PollVoteStatistics] -> ShowS
Show)

instance I.ShortShow PollVoteStatistics where
  shortShow :: PollVoteStatistics -> String
shortShow PollVoteStatistics
    { vote_graph :: PollVoteStatistics -> Maybe StatisticalGraph
vote_graph = Maybe StatisticalGraph
vote_graph_
    }
      = String
"PollVoteStatistics"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"vote_graph" String -> Maybe StatisticalGraph -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StatisticalGraph
vote_graph_
        ]

instance AT.FromJSON PollVoteStatistics where
  parseJSON :: Value -> Parser PollVoteStatistics
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
"pollVoteStatistics" -> Value -> Parser PollVoteStatistics
parsePollVoteStatistics Value
v
      String
_                    -> Parser PollVoteStatistics
forall a. Monoid a => a
mempty
    
    where
      parsePollVoteStatistics :: A.Value -> AT.Parser PollVoteStatistics
      parsePollVoteStatistics :: Value -> Parser PollVoteStatistics
parsePollVoteStatistics = String
-> (Object -> Parser PollVoteStatistics)
-> Value
-> Parser PollVoteStatistics
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PollVoteStatistics" ((Object -> Parser PollVoteStatistics)
 -> Value -> Parser PollVoteStatistics)
-> (Object -> Parser PollVoteStatistics)
-> Value
-> Parser PollVoteStatistics
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe StatisticalGraph
vote_graph_ <- Object
o Object -> Key -> Parser (Maybe StatisticalGraph)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"vote_graph"
        PollVoteStatistics -> Parser PollVoteStatistics
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PollVoteStatistics -> Parser PollVoteStatistics)
-> PollVoteStatistics -> Parser PollVoteStatistics
forall a b. (a -> b) -> a -> b
$ PollVoteStatistics
          { vote_graph :: Maybe StatisticalGraph
vote_graph = Maybe StatisticalGraph
vote_graph_
          }
  parseJSON Value
_ = Parser PollVoteStatistics
forall a. Monoid a => a
mempty