{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Commands.StakePool
  ( StakePoolCmds (..)
  , renderStakePoolCmds
  , StakePoolDeregistrationCertificateCmdArgs (..)
  , StakePoolIdCmdArgs (..)
  , StakePoolMetadataHashCmdArgs (..)
  , StakePoolRegistrationCertificateCmdArgs (..)
  , StakePoolMetadataSource (..)
  )
where

import           Cardano.Api.Ledger (Coin)
import qualified Cardano.Api.Ledger as L
import           Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..))

import           Cardano.CLI.Commands.Hash (HashGoal)
import           Cardano.CLI.Types.Common
import           Cardano.CLI.Types.Key

import           Prelude

import           Data.Text (Text)

data StakePoolCmds era
  = StakePoolDeregistrationCertificateCmd !(StakePoolDeregistrationCertificateCmdArgs era)
  | StakePoolIdCmd !(StakePoolIdCmdArgs era)
  | StakePoolMetadataHashCmd !(StakePoolMetadataHashCmdArgs era)
  | StakePoolRegistrationCertificateCmd !(StakePoolRegistrationCertificateCmdArgs era)
  deriving Int -> StakePoolCmds era -> ShowS
[StakePoolCmds era] -> ShowS
StakePoolCmds era -> String
(Int -> StakePoolCmds era -> ShowS)
-> (StakePoolCmds era -> String)
-> ([StakePoolCmds era] -> ShowS)
-> Show (StakePoolCmds era)
forall era. Int -> StakePoolCmds era -> ShowS
forall era. [StakePoolCmds era] -> ShowS
forall era. StakePoolCmds era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall era. Int -> StakePoolCmds era -> ShowS
showsPrec :: Int -> StakePoolCmds era -> ShowS
$cshow :: forall era. StakePoolCmds era -> String
show :: StakePoolCmds era -> String
$cshowList :: forall era. [StakePoolCmds era] -> ShowS
showList :: [StakePoolCmds era] -> ShowS
Show

data StakePoolDeregistrationCertificateCmdArgs era
  = StakePoolDeregistrationCertificateCmdArgs
  { forall era.
StakePoolDeregistrationCertificateCmdArgs era
-> ShelleyBasedEra era
sbe :: !(ShelleyBasedEra era)
  , forall era.
StakePoolDeregistrationCertificateCmdArgs era
-> VerificationKeyOrFile StakePoolKey
poolVerificationKeyOrFile :: !(VerificationKeyOrFile StakePoolKey)
  , forall era.
StakePoolDeregistrationCertificateCmdArgs era -> EpochNo
retireEpoch :: !EpochNo
  , forall era.
StakePoolDeregistrationCertificateCmdArgs era -> File () 'Out
outFile :: !(File () Out)
  }
  deriving Int -> StakePoolDeregistrationCertificateCmdArgs era -> ShowS
[StakePoolDeregistrationCertificateCmdArgs era] -> ShowS
StakePoolDeregistrationCertificateCmdArgs era -> String
(Int -> StakePoolDeregistrationCertificateCmdArgs era -> ShowS)
-> (StakePoolDeregistrationCertificateCmdArgs era -> String)
-> ([StakePoolDeregistrationCertificateCmdArgs era] -> ShowS)
-> Show (StakePoolDeregistrationCertificateCmdArgs era)
forall era.
Int -> StakePoolDeregistrationCertificateCmdArgs era -> ShowS
forall era.
[StakePoolDeregistrationCertificateCmdArgs era] -> ShowS
forall era. StakePoolDeregistrationCertificateCmdArgs era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall era.
Int -> StakePoolDeregistrationCertificateCmdArgs era -> ShowS
showsPrec :: Int -> StakePoolDeregistrationCertificateCmdArgs era -> ShowS
$cshow :: forall era. StakePoolDeregistrationCertificateCmdArgs era -> String
show :: StakePoolDeregistrationCertificateCmdArgs era -> String
$cshowList :: forall era.
[StakePoolDeregistrationCertificateCmdArgs era] -> ShowS
showList :: [StakePoolDeregistrationCertificateCmdArgs era] -> ShowS
Show

data StakePoolIdCmdArgs era
  = StakePoolIdCmdArgs
  { forall era.
StakePoolIdCmdArgs era -> VerificationKeyOrFile StakePoolKey
poolVerificationKeyOrFile :: !(VerificationKeyOrFile StakePoolKey)
  , forall era. StakePoolIdCmdArgs era -> IdOutputFormat
outputFormat :: !IdOutputFormat
  , forall era. StakePoolIdCmdArgs era -> Maybe (File () 'Out)
mOutFile :: !(Maybe (File () Out))
  }
  deriving Int -> StakePoolIdCmdArgs era -> ShowS
[StakePoolIdCmdArgs era] -> ShowS
StakePoolIdCmdArgs era -> String
(Int -> StakePoolIdCmdArgs era -> ShowS)
-> (StakePoolIdCmdArgs era -> String)
-> ([StakePoolIdCmdArgs era] -> ShowS)
-> Show (StakePoolIdCmdArgs era)
forall era. Int -> StakePoolIdCmdArgs era -> ShowS
forall era. [StakePoolIdCmdArgs era] -> ShowS
forall era. StakePoolIdCmdArgs era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall era. Int -> StakePoolIdCmdArgs era -> ShowS
showsPrec :: Int -> StakePoolIdCmdArgs era -> ShowS
$cshow :: forall era. StakePoolIdCmdArgs era -> String
show :: StakePoolIdCmdArgs era -> String
$cshowList :: forall era. [StakePoolIdCmdArgs era] -> ShowS
showList :: [StakePoolIdCmdArgs era] -> ShowS
Show

data StakePoolMetadataHashCmdArgs era
  = StakePoolMetadataHashCmdArgs
  { forall era.
StakePoolMetadataHashCmdArgs era -> StakePoolMetadataSource
poolMetadataSource :: !StakePoolMetadataSource
  , forall era.
StakePoolMetadataHashCmdArgs era
-> HashGoal (Hash StakePoolMetadata)
hashGoal :: !(HashGoal (Hash StakePoolMetadata))
  }
  deriving Int -> StakePoolMetadataHashCmdArgs era -> ShowS
[StakePoolMetadataHashCmdArgs era] -> ShowS
StakePoolMetadataHashCmdArgs era -> String
(Int -> StakePoolMetadataHashCmdArgs era -> ShowS)
-> (StakePoolMetadataHashCmdArgs era -> String)
-> ([StakePoolMetadataHashCmdArgs era] -> ShowS)
-> Show (StakePoolMetadataHashCmdArgs era)
forall era. Int -> StakePoolMetadataHashCmdArgs era -> ShowS
forall era. [StakePoolMetadataHashCmdArgs era] -> ShowS
forall era. StakePoolMetadataHashCmdArgs era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall era. Int -> StakePoolMetadataHashCmdArgs era -> ShowS
showsPrec :: Int -> StakePoolMetadataHashCmdArgs era -> ShowS
$cshow :: forall era. StakePoolMetadataHashCmdArgs era -> String
show :: StakePoolMetadataHashCmdArgs era -> String
$cshowList :: forall era. [StakePoolMetadataHashCmdArgs era] -> ShowS
showList :: [StakePoolMetadataHashCmdArgs era] -> ShowS
Show

data StakePoolMetadataSource
  = StakePoolMetadataFileIn !(StakePoolMetadataFile In)
  | StakePoolMetadataURL !L.Url
  deriving Int -> StakePoolMetadataSource -> ShowS
[StakePoolMetadataSource] -> ShowS
StakePoolMetadataSource -> String
(Int -> StakePoolMetadataSource -> ShowS)
-> (StakePoolMetadataSource -> String)
-> ([StakePoolMetadataSource] -> ShowS)
-> Show StakePoolMetadataSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StakePoolMetadataSource -> ShowS
showsPrec :: Int -> StakePoolMetadataSource -> ShowS
$cshow :: StakePoolMetadataSource -> String
show :: StakePoolMetadataSource -> String
$cshowList :: [StakePoolMetadataSource] -> ShowS
showList :: [StakePoolMetadataSource] -> ShowS
Show

data StakePoolRegistrationCertificateCmdArgs era
  = StakePoolRegistrationCertificateCmdArgs
  { forall era.
StakePoolRegistrationCertificateCmdArgs era -> ShelleyBasedEra era
sbe :: !(ShelleyBasedEra era)
  -- ^ Era in which to register the stake pool.
  , forall era.
StakePoolRegistrationCertificateCmdArgs era
-> VerificationKeyOrFile StakePoolKey
poolVerificationKeyOrFile :: !(VerificationKeyOrFile StakePoolKey)
  -- ^ Stake pool verification key.
  , forall era.
StakePoolRegistrationCertificateCmdArgs era
-> VerificationKeyOrFile VrfKey
vrfVerificationKeyOrFile :: !(VerificationKeyOrFile VrfKey)
  -- ^ VRF Verification key.
  , forall era. StakePoolRegistrationCertificateCmdArgs era -> Coin
poolPledge :: !Coin
  -- ^ Pool pledge.
  , forall era. StakePoolRegistrationCertificateCmdArgs era -> Coin
poolCost :: !Coin
  -- ^ Pool cost.
  , forall era. StakePoolRegistrationCertificateCmdArgs era -> Rational
poolMargin :: !Rational
  -- ^ Pool margin.
  , forall era.
StakePoolRegistrationCertificateCmdArgs era
-> VerificationKeyOrFile StakeKey
rewardStakeVerificationKeyOrFile :: !(VerificationKeyOrFile StakeKey)
  -- ^ Reward account verification staking key.
  , forall era.
StakePoolRegistrationCertificateCmdArgs era
-> [VerificationKeyOrFile StakeKey]
ownerStakeVerificationKeyOrFiles :: ![VerificationKeyOrFile StakeKey]
  -- ^ Pool owner verification staking key(s).
  , forall era.
StakePoolRegistrationCertificateCmdArgs era -> [StakePoolRelay]
relays :: ![StakePoolRelay]
  -- ^ Stake pool relays.
  , forall era.
StakePoolRegistrationCertificateCmdArgs era
-> Maybe
     (PotentiallyCheckedAnchor
        StakePoolMetadataReference StakePoolMetadataReference)
mMetadata
      :: !(Maybe (PotentiallyCheckedAnchor StakePoolMetadataReference StakePoolMetadataReference))
  -- ^ Stake pool metadata.
  , forall era.
StakePoolRegistrationCertificateCmdArgs era -> NetworkId
network :: !NetworkId
  , forall era.
StakePoolRegistrationCertificateCmdArgs era -> File () 'Out
outFile :: !(File () Out)
  }
  deriving Int -> StakePoolRegistrationCertificateCmdArgs era -> ShowS
[StakePoolRegistrationCertificateCmdArgs era] -> ShowS
StakePoolRegistrationCertificateCmdArgs era -> String
(Int -> StakePoolRegistrationCertificateCmdArgs era -> ShowS)
-> (StakePoolRegistrationCertificateCmdArgs era -> String)
-> ([StakePoolRegistrationCertificateCmdArgs era] -> ShowS)
-> Show (StakePoolRegistrationCertificateCmdArgs era)
forall era.
Int -> StakePoolRegistrationCertificateCmdArgs era -> ShowS
forall era. [StakePoolRegistrationCertificateCmdArgs era] -> ShowS
forall era. StakePoolRegistrationCertificateCmdArgs era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall era.
Int -> StakePoolRegistrationCertificateCmdArgs era -> ShowS
showsPrec :: Int -> StakePoolRegistrationCertificateCmdArgs era -> ShowS
$cshow :: forall era. StakePoolRegistrationCertificateCmdArgs era -> String
show :: StakePoolRegistrationCertificateCmdArgs era -> String
$cshowList :: forall era. [StakePoolRegistrationCertificateCmdArgs era] -> ShowS
showList :: [StakePoolRegistrationCertificateCmdArgs era] -> ShowS
Show

renderStakePoolCmds :: StakePoolCmds era -> Text
renderStakePoolCmds :: forall era. StakePoolCmds era -> Text
renderStakePoolCmds = \case
  StakePoolDeregistrationCertificateCmd{} ->
    Text
"stake-pool deregistration-certificate"
  StakePoolIdCmd{} ->
    Text
"stake-pool id"
  StakePoolMetadataHashCmd{} ->
    Text
"stake-pool metadata-hash"
  StakePoolRegistrationCertificateCmd{} ->
    Text
"stake-pool registration-certificate"