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

module Cardano.CLI.Commands.Node
  ( NodeCmds (..)
  , renderNodeCmds
  , NodeKeyGenColdCmdArgs (..)
  , NodeKeyGenKESCmdArgs (..)
  , NodeKeyGenVRFCmdArgs (..)
  , NodeKeyHashVRFCmdArgs (..)
  , NodeNewCounterCmdArgs (..)
  , NodeIssueOpCertCmdArgs (..)
  )
where

import           Cardano.Api.Shelley

import           Cardano.CLI.Types.Common
import           Cardano.CLI.Types.Key

import           Data.Text (Text)

data NodeCmds
  = NodeKeyGenColdCmd !NodeKeyGenColdCmdArgs
  | NodeKeyGenKESCmd !NodeKeyGenKESCmdArgs
  | NodeKeyGenVRFCmd !NodeKeyGenVRFCmdArgs
  | NodeKeyHashVRFCmd !NodeKeyHashVRFCmdArgs
  | NodeNewCounterCmd !NodeNewCounterCmdArgs
  | NodeIssueOpCertCmd !NodeIssueOpCertCmdArgs
  deriving Int -> NodeCmds -> ShowS
[NodeCmds] -> ShowS
NodeCmds -> String
(Int -> NodeCmds -> ShowS)
-> (NodeCmds -> String) -> ([NodeCmds] -> ShowS) -> Show NodeCmds
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NodeCmds -> ShowS
showsPrec :: Int -> NodeCmds -> ShowS
$cshow :: NodeCmds -> String
show :: NodeCmds -> String
$cshowList :: [NodeCmds] -> ShowS
showList :: [NodeCmds] -> ShowS
Show

data NodeKeyGenColdCmdArgs
  = NodeKeyGenColdCmdArgs
  { NodeKeyGenColdCmdArgs -> KeyOutputFormat
keyOutputFormat :: !KeyOutputFormat
  , NodeKeyGenColdCmdArgs -> VerificationKeyFile 'Out
vkeyFile :: !(VerificationKeyFile Out)
  , NodeKeyGenColdCmdArgs -> SigningKeyFile 'Out
skeyFile :: !(SigningKeyFile Out)
  , NodeKeyGenColdCmdArgs -> OpCertCounterFile 'Out
operationalCertificateIssueCounter :: !(OpCertCounterFile Out)
  }
  deriving Int -> NodeKeyGenColdCmdArgs -> ShowS
[NodeKeyGenColdCmdArgs] -> ShowS
NodeKeyGenColdCmdArgs -> String
(Int -> NodeKeyGenColdCmdArgs -> ShowS)
-> (NodeKeyGenColdCmdArgs -> String)
-> ([NodeKeyGenColdCmdArgs] -> ShowS)
-> Show NodeKeyGenColdCmdArgs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NodeKeyGenColdCmdArgs -> ShowS
showsPrec :: Int -> NodeKeyGenColdCmdArgs -> ShowS
$cshow :: NodeKeyGenColdCmdArgs -> String
show :: NodeKeyGenColdCmdArgs -> String
$cshowList :: [NodeKeyGenColdCmdArgs] -> ShowS
showList :: [NodeKeyGenColdCmdArgs] -> ShowS
Show

data NodeKeyGenKESCmdArgs
  = NodeKeyGenKESCmdArgs
  { NodeKeyGenKESCmdArgs -> KeyOutputFormat
keyOutputFormat :: !KeyOutputFormat
  , NodeKeyGenKESCmdArgs -> VerificationKeyFile 'Out
vkeyFile :: !(VerificationKeyFile Out)
  , NodeKeyGenKESCmdArgs -> SigningKeyFile 'Out
skeyFile :: !(SigningKeyFile Out)
  }
  deriving Int -> NodeKeyGenKESCmdArgs -> ShowS
[NodeKeyGenKESCmdArgs] -> ShowS
NodeKeyGenKESCmdArgs -> String
(Int -> NodeKeyGenKESCmdArgs -> ShowS)
-> (NodeKeyGenKESCmdArgs -> String)
-> ([NodeKeyGenKESCmdArgs] -> ShowS)
-> Show NodeKeyGenKESCmdArgs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NodeKeyGenKESCmdArgs -> ShowS
showsPrec :: Int -> NodeKeyGenKESCmdArgs -> ShowS
$cshow :: NodeKeyGenKESCmdArgs -> String
show :: NodeKeyGenKESCmdArgs -> String
$cshowList :: [NodeKeyGenKESCmdArgs] -> ShowS
showList :: [NodeKeyGenKESCmdArgs] -> ShowS
Show

data NodeKeyGenVRFCmdArgs
  = NodeKeyGenVRFCmdArgs
  { NodeKeyGenVRFCmdArgs -> KeyOutputFormat
keyOutputFormat :: !KeyOutputFormat
  , NodeKeyGenVRFCmdArgs -> VerificationKeyFile 'Out
vkeyFile :: !(VerificationKeyFile Out)
  , NodeKeyGenVRFCmdArgs -> SigningKeyFile 'Out
skeyFile :: !(SigningKeyFile Out)
  }
  deriving Int -> NodeKeyGenVRFCmdArgs -> ShowS
[NodeKeyGenVRFCmdArgs] -> ShowS
NodeKeyGenVRFCmdArgs -> String
(Int -> NodeKeyGenVRFCmdArgs -> ShowS)
-> (NodeKeyGenVRFCmdArgs -> String)
-> ([NodeKeyGenVRFCmdArgs] -> ShowS)
-> Show NodeKeyGenVRFCmdArgs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NodeKeyGenVRFCmdArgs -> ShowS
showsPrec :: Int -> NodeKeyGenVRFCmdArgs -> ShowS
$cshow :: NodeKeyGenVRFCmdArgs -> String
show :: NodeKeyGenVRFCmdArgs -> String
$cshowList :: [NodeKeyGenVRFCmdArgs] -> ShowS
showList :: [NodeKeyGenVRFCmdArgs] -> ShowS
Show

data NodeKeyHashVRFCmdArgs
  = NodeKeyHashVRFCmdArgs
  { NodeKeyHashVRFCmdArgs -> VerificationKeyOrFile VrfKey
vkeySource :: !(VerificationKeyOrFile VrfKey)
  , NodeKeyHashVRFCmdArgs -> Maybe (File () 'Out)
mOutFile :: !(Maybe (File () Out))
  }
  deriving Int -> NodeKeyHashVRFCmdArgs -> ShowS
[NodeKeyHashVRFCmdArgs] -> ShowS
NodeKeyHashVRFCmdArgs -> String
(Int -> NodeKeyHashVRFCmdArgs -> ShowS)
-> (NodeKeyHashVRFCmdArgs -> String)
-> ([NodeKeyHashVRFCmdArgs] -> ShowS)
-> Show NodeKeyHashVRFCmdArgs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NodeKeyHashVRFCmdArgs -> ShowS
showsPrec :: Int -> NodeKeyHashVRFCmdArgs -> ShowS
$cshow :: NodeKeyHashVRFCmdArgs -> String
show :: NodeKeyHashVRFCmdArgs -> String
$cshowList :: [NodeKeyHashVRFCmdArgs] -> ShowS
showList :: [NodeKeyHashVRFCmdArgs] -> ShowS
Show

data NodeNewCounterCmdArgs
  = NodeNewCounterCmdArgs
  { NodeNewCounterCmdArgs -> ColdVerificationKeyOrFile
coldVkeyFile :: !ColdVerificationKeyOrFile
  , NodeNewCounterCmdArgs -> Word
counter :: !Word
  , NodeNewCounterCmdArgs -> OpCertCounterFile 'InOut
mOutFile :: !(OpCertCounterFile InOut)
  }
  deriving Int -> NodeNewCounterCmdArgs -> ShowS
[NodeNewCounterCmdArgs] -> ShowS
NodeNewCounterCmdArgs -> String
(Int -> NodeNewCounterCmdArgs -> ShowS)
-> (NodeNewCounterCmdArgs -> String)
-> ([NodeNewCounterCmdArgs] -> ShowS)
-> Show NodeNewCounterCmdArgs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NodeNewCounterCmdArgs -> ShowS
showsPrec :: Int -> NodeNewCounterCmdArgs -> ShowS
$cshow :: NodeNewCounterCmdArgs -> String
show :: NodeNewCounterCmdArgs -> String
$cshowList :: [NodeNewCounterCmdArgs] -> ShowS
showList :: [NodeNewCounterCmdArgs] -> ShowS
Show

data NodeIssueOpCertCmdArgs
  = NodeIssueOpCertCmdArgs
  { NodeIssueOpCertCmdArgs -> VerificationKeyOrFile KesKey
kesVkeySource :: !(VerificationKeyOrFile KesKey)
  -- ^ The hot KES verification key.
  , NodeIssueOpCertCmdArgs -> SigningKeyFile 'In
poolSkeyFile :: !(SigningKeyFile In)
  -- ^ The cold signing key.
  , NodeIssueOpCertCmdArgs -> OpCertCounterFile 'InOut
operationalCertificateCounterFile :: !(OpCertCounterFile InOut)
  -- ^ Counter that establishes the precedence of the operational certificate.
  , NodeIssueOpCertCmdArgs -> KESPeriod
kesPeriod :: !KESPeriod
  -- ^ Start of the validity period for this certificate.
  , NodeIssueOpCertCmdArgs -> File () 'Out
outFile :: !(File () Out)
  }
  deriving Int -> NodeIssueOpCertCmdArgs -> ShowS
[NodeIssueOpCertCmdArgs] -> ShowS
NodeIssueOpCertCmdArgs -> String
(Int -> NodeIssueOpCertCmdArgs -> ShowS)
-> (NodeIssueOpCertCmdArgs -> String)
-> ([NodeIssueOpCertCmdArgs] -> ShowS)
-> Show NodeIssueOpCertCmdArgs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NodeIssueOpCertCmdArgs -> ShowS
showsPrec :: Int -> NodeIssueOpCertCmdArgs -> ShowS
$cshow :: NodeIssueOpCertCmdArgs -> String
show :: NodeIssueOpCertCmdArgs -> String
$cshowList :: [NodeIssueOpCertCmdArgs] -> ShowS
showList :: [NodeIssueOpCertCmdArgs] -> ShowS
Show

renderNodeCmds :: NodeCmds -> Text
renderNodeCmds :: NodeCmds -> Text
renderNodeCmds = \case
  NodeKeyGenColdCmd{} -> Text
"node key-gen"
  NodeKeyGenKESCmd{} -> Text
"node key-gen-KES"
  NodeKeyGenVRFCmd{} -> Text
"node key-gen-VRF"
  NodeKeyHashVRFCmd{} -> Text
"node key-hash-VRF"
  NodeNewCounterCmd{} -> Text
"node new-counter"
  NodeIssueOpCertCmd{} -> Text
"node issue-op-cert"