-- | Cardano Network reponses

{-# LANGUAGE NumericUnderscores #-}

module Blockfrost.Types.Cardano.Network
  ( Network (..)
  , NetworkStake (..)
  , NetworkSupply (..)
  ) where

import Deriving.Aeson
import Servant.Docs (ToSample (..), singleSample)

import Blockfrost.Types.Shared

-- | Lovelace supply data
data NetworkSupply = NetworkSupply
  { NetworkSupply -> Lovelaces
_supplyMax         :: Lovelaces -- ^ Maximum supply in Lovelaces
  , NetworkSupply -> Lovelaces
_supplyTotal       :: Lovelaces -- ^ Current total (max supply - reserves) supply in Lovelaces
  , NetworkSupply -> Lovelaces
_supplyCirculating :: Lovelaces -- ^ Current circulating (UTXOs + withdrawables) supply in Lovelaces
  , NetworkSupply -> Lovelaces
_supplyLocked      :: Lovelaces -- ^ Current supply locked by scripts in Lovelaces
  , NetworkSupply -> Lovelaces
_supplyTreasury    :: Lovelaces -- ^ Current supply locked in treasury
  , NetworkSupply -> Lovelaces
_supplyReserves    :: Lovelaces -- ^ Current supply locked in reserves
  }
  deriving stock (Int -> NetworkSupply -> ShowS
[NetworkSupply] -> ShowS
NetworkSupply -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NetworkSupply] -> ShowS
$cshowList :: [NetworkSupply] -> ShowS
show :: NetworkSupply -> String
$cshow :: NetworkSupply -> String
showsPrec :: Int -> NetworkSupply -> ShowS
$cshowsPrec :: Int -> NetworkSupply -> ShowS
Show, NetworkSupply -> NetworkSupply -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NetworkSupply -> NetworkSupply -> Bool
$c/= :: NetworkSupply -> NetworkSupply -> Bool
== :: NetworkSupply -> NetworkSupply -> Bool
$c== :: NetworkSupply -> NetworkSupply -> Bool
Eq, forall x. Rep NetworkSupply x -> NetworkSupply
forall x. NetworkSupply -> Rep NetworkSupply x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NetworkSupply x -> NetworkSupply
$cfrom :: forall x. NetworkSupply -> Rep NetworkSupply x
Generic)
  deriving (Value -> Parser [NetworkSupply]
Value -> Parser NetworkSupply
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [NetworkSupply]
$cparseJSONList :: Value -> Parser [NetworkSupply]
parseJSON :: Value -> Parser NetworkSupply
$cparseJSON :: Value -> Parser NetworkSupply
FromJSON, [NetworkSupply] -> Encoding
[NetworkSupply] -> Value
NetworkSupply -> Encoding
NetworkSupply -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [NetworkSupply] -> Encoding
$ctoEncodingList :: [NetworkSupply] -> Encoding
toJSONList :: [NetworkSupply] -> Value
$ctoJSONList :: [NetworkSupply] -> Value
toEncoding :: NetworkSupply -> Encoding
$ctoEncoding :: NetworkSupply -> Encoding
toJSON :: NetworkSupply -> Value
$ctoJSON :: NetworkSupply -> Value
ToJSON)
  via CustomJSON '[FieldLabelModifier '[StripPrefix "_supply", CamelToSnake]] NetworkSupply

netSupplySample :: NetworkSupply
netSupplySample :: NetworkSupply
netSupplySample =
  NetworkSupply
    { _supplyMax :: Lovelaces
_supplyMax = Discrete' "ADA" '(1000000, 1)
45_000_000_000_000_000
    , _supplyTotal :: Lovelaces
_supplyTotal = Discrete' "ADA" '(1000000, 1)
32_890_715_183_299_160
    , _supplyCirculating :: Lovelaces
_supplyCirculating = Discrete' "ADA" '(1000000, 1)
32_412_601_976_210_393
    , _supplyLocked :: Lovelaces
_supplyLocked = Discrete' "ADA" '(1000000, 1)
125_006_953_355
    , _supplyTreasury :: Lovelaces
_supplyTreasury = Discrete' "ADA" '(1000000, 1)
98_635_632_000_000
    , _supplyReserves :: Lovelaces
_supplyReserves = Discrete' "ADA" '(1000000, 1)
46_635_632_000_000
    }

instance ToSample NetworkSupply where
  toSamples :: Proxy NetworkSupply -> [(Text, NetworkSupply)]
toSamples = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. a -> [(Text, a)]
singleSample NetworkSupply
netSupplySample

-- | Live and active stake of the whole network
data NetworkStake = NetworkStake
  { NetworkStake -> Lovelaces
_stakeLive   :: Lovelaces -- ^ Current live stake in Lovelaces
  , NetworkStake -> Lovelaces
_stakeActive :: Lovelaces -- ^ Current active stake in Lovelaces
  }
  deriving stock (Int -> NetworkStake -> ShowS
[NetworkStake] -> ShowS
NetworkStake -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NetworkStake] -> ShowS
$cshowList :: [NetworkStake] -> ShowS
show :: NetworkStake -> String
$cshow :: NetworkStake -> String
showsPrec :: Int -> NetworkStake -> ShowS
$cshowsPrec :: Int -> NetworkStake -> ShowS
Show, NetworkStake -> NetworkStake -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NetworkStake -> NetworkStake -> Bool
$c/= :: NetworkStake -> NetworkStake -> Bool
== :: NetworkStake -> NetworkStake -> Bool
$c== :: NetworkStake -> NetworkStake -> Bool
Eq, forall x. Rep NetworkStake x -> NetworkStake
forall x. NetworkStake -> Rep NetworkStake x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NetworkStake x -> NetworkStake
$cfrom :: forall x. NetworkStake -> Rep NetworkStake x
Generic)
  deriving (Value -> Parser [NetworkStake]
Value -> Parser NetworkStake
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [NetworkStake]
$cparseJSONList :: Value -> Parser [NetworkStake]
parseJSON :: Value -> Parser NetworkStake
$cparseJSON :: Value -> Parser NetworkStake
FromJSON, [NetworkStake] -> Encoding
[NetworkStake] -> Value
NetworkStake -> Encoding
NetworkStake -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [NetworkStake] -> Encoding
$ctoEncodingList :: [NetworkStake] -> Encoding
toJSONList :: [NetworkStake] -> Value
$ctoJSONList :: [NetworkStake] -> Value
toEncoding :: NetworkStake -> Encoding
$ctoEncoding :: NetworkStake -> Encoding
toJSON :: NetworkStake -> Value
$ctoJSON :: NetworkStake -> Value
ToJSON)
  via CustomJSON '[FieldLabelModifier '[StripPrefix "_stake", CamelToSnake]] NetworkStake

netStakeSample :: NetworkStake
netStakeSample :: NetworkStake
netStakeSample =
  NetworkStake
    { _stakeLive :: Lovelaces
_stakeLive = Discrete' "ADA" '(1000000, 1)
23_204_950_463_991_654
    , _stakeActive :: Lovelaces
_stakeActive = Discrete' "ADA" '(1000000, 1)
22_210_233_523_456_321
    }

instance ToSample NetworkStake where
  toSamples :: Proxy NetworkStake -> [(Text, NetworkStake)]
toSamples = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. a -> [(Text, a)]
singleSample NetworkStake
netStakeSample

-- | Detailed network information
data Network = Network
  { Network -> NetworkSupply
_networkSupply :: NetworkSupply -- ^ Supply data
  , Network -> NetworkStake
_networkStake  :: NetworkStake -- ^ Stake data
  }
  deriving stock (Int -> Network -> ShowS
[Network] -> ShowS
Network -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Network] -> ShowS
$cshowList :: [Network] -> ShowS
show :: Network -> String
$cshow :: Network -> String
showsPrec :: Int -> Network -> ShowS
$cshowsPrec :: Int -> Network -> ShowS
Show, Network -> Network -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Network -> Network -> Bool
$c/= :: Network -> Network -> Bool
== :: Network -> Network -> Bool
$c== :: Network -> Network -> Bool
Eq, forall x. Rep Network x -> Network
forall x. Network -> Rep Network x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Network x -> Network
$cfrom :: forall x. Network -> Rep Network x
Generic)
  deriving (Value -> Parser [Network]
Value -> Parser Network
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Network]
$cparseJSONList :: Value -> Parser [Network]
parseJSON :: Value -> Parser Network
$cparseJSON :: Value -> Parser Network
FromJSON, [Network] -> Encoding
[Network] -> Value
Network -> Encoding
Network -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Network] -> Encoding
$ctoEncodingList :: [Network] -> Encoding
toJSONList :: [Network] -> Value
$ctoJSONList :: [Network] -> Value
toEncoding :: Network -> Encoding
$ctoEncoding :: Network -> Encoding
toJSON :: Network -> Value
$ctoJSON :: Network -> Value
ToJSON)
  via CustomJSON '[FieldLabelModifier '[StripPrefix "_network", CamelToSnake]] Network

instance ToSample Network where
  toSamples :: Proxy Network -> [(Text, Network)]
toSamples = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. a -> [(Text, a)]
singleSample forall a b. (a -> b) -> a -> b
$
    NetworkSupply -> NetworkStake -> Network
Network NetworkSupply
netSupplySample NetworkStake
netStakeSample