module TD.Data.TonRevenueStatistics
  (TonRevenueStatistics(..)) 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
import qualified TD.Data.TonRevenueStatus as TonRevenueStatus

data TonRevenueStatistics
  = TonRevenueStatistics -- ^ A detailed statistics about Toncoins earned by the current user
    { TonRevenueStatistics -> Maybe StatisticalGraph
revenue_by_day_graph :: Maybe StatisticalGraph.StatisticalGraph -- ^ A graph containing amount of revenue in a given day
    , TonRevenueStatistics -> Maybe TonRevenueStatus
status               :: Maybe TonRevenueStatus.TonRevenueStatus -- ^ Amount of earned revenue
    , TonRevenueStatistics -> Maybe Double
usd_rate             :: Maybe Double                            -- ^ Current conversion rate of nanotoncoin to USD cents
    }
  deriving (TonRevenueStatistics -> TonRevenueStatistics -> Bool
(TonRevenueStatistics -> TonRevenueStatistics -> Bool)
-> (TonRevenueStatistics -> TonRevenueStatistics -> Bool)
-> Eq TonRevenueStatistics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TonRevenueStatistics -> TonRevenueStatistics -> Bool
== :: TonRevenueStatistics -> TonRevenueStatistics -> Bool
$c/= :: TonRevenueStatistics -> TonRevenueStatistics -> Bool
/= :: TonRevenueStatistics -> TonRevenueStatistics -> Bool
Eq, Int -> TonRevenueStatistics -> ShowS
[TonRevenueStatistics] -> ShowS
TonRevenueStatistics -> String
(Int -> TonRevenueStatistics -> ShowS)
-> (TonRevenueStatistics -> String)
-> ([TonRevenueStatistics] -> ShowS)
-> Show TonRevenueStatistics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TonRevenueStatistics -> ShowS
showsPrec :: Int -> TonRevenueStatistics -> ShowS
$cshow :: TonRevenueStatistics -> String
show :: TonRevenueStatistics -> String
$cshowList :: [TonRevenueStatistics] -> ShowS
showList :: [TonRevenueStatistics] -> ShowS
Show)

instance I.ShortShow TonRevenueStatistics where
  shortShow :: TonRevenueStatistics -> String
shortShow TonRevenueStatistics
    { revenue_by_day_graph :: TonRevenueStatistics -> Maybe StatisticalGraph
revenue_by_day_graph = Maybe StatisticalGraph
revenue_by_day_graph_
    , status :: TonRevenueStatistics -> Maybe TonRevenueStatus
status               = Maybe TonRevenueStatus
status_
    , usd_rate :: TonRevenueStatistics -> Maybe Double
usd_rate             = Maybe Double
usd_rate_
    }
      = String
"TonRevenueStatistics"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"revenue_by_day_graph" String -> Maybe StatisticalGraph -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StatisticalGraph
revenue_by_day_graph_
        , String
"status"               String -> Maybe TonRevenueStatus -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe TonRevenueStatus
status_
        , String
"usd_rate"             String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
usd_rate_
        ]

instance AT.FromJSON TonRevenueStatistics where
  parseJSON :: Value -> Parser TonRevenueStatistics
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
"tonRevenueStatistics" -> Value -> Parser TonRevenueStatistics
parseTonRevenueStatistics Value
v
      String
_                      -> Parser TonRevenueStatistics
forall a. Monoid a => a
mempty
    
    where
      parseTonRevenueStatistics :: A.Value -> AT.Parser TonRevenueStatistics
      parseTonRevenueStatistics :: Value -> Parser TonRevenueStatistics
parseTonRevenueStatistics = String
-> (Object -> Parser TonRevenueStatistics)
-> Value
-> Parser TonRevenueStatistics
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TonRevenueStatistics" ((Object -> Parser TonRevenueStatistics)
 -> Value -> Parser TonRevenueStatistics)
-> (Object -> Parser TonRevenueStatistics)
-> Value
-> Parser TonRevenueStatistics
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe StatisticalGraph
revenue_by_day_graph_ <- Object
o Object -> Key -> Parser (Maybe StatisticalGraph)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"revenue_by_day_graph"
        Maybe TonRevenueStatus
status_               <- Object
o Object -> Key -> Parser (Maybe TonRevenueStatus)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"status"
        Maybe Double
usd_rate_             <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"usd_rate"
        TonRevenueStatistics -> Parser TonRevenueStatistics
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TonRevenueStatistics -> Parser TonRevenueStatistics)
-> TonRevenueStatistics -> Parser TonRevenueStatistics
forall a b. (a -> b) -> a -> b
$ TonRevenueStatistics
          { revenue_by_day_graph :: Maybe StatisticalGraph
revenue_by_day_graph = Maybe StatisticalGraph
revenue_by_day_graph_
          , status :: Maybe TonRevenueStatus
status               = Maybe TonRevenueStatus
status_
          , usd_rate :: Maybe Double
usd_rate             = Maybe Double
usd_rate_
          }
  parseJSON Value
_ = Parser TonRevenueStatistics
forall a. Monoid a => a
mempty