{-# LANGUAGE GeneralisedNewtypeDeriving #-}

module Cardano.CLI.Byron.Commands
  ( ByronCommand (..)
  , NodeCmd (..)
  , VerificationKeyFile (..)
  , NewVerificationKeyFile (..)
  , CertificateFile (..)
  , NewCertificateFile (..)
  ) where

import           Cardano.Prelude

import           Cardano.Chain.Slotting (EpochNumber (..))
import           Cardano.Chain.Update (InstallerHash (..), ProtocolVersion (..),
                     SoftwareVersion (..), SystemTag (..))

import           Cardano.Api.Typed (NetworkId)

import           Cardano.CLI.Byron.UpdateProposal

import           Cardano.CLI.Byron.Genesis
import           Cardano.CLI.Byron.Key
import           Cardano.CLI.Byron.Tx
import           Cardano.CLI.Types

import           Cardano.Chain.Common (Address (..))
import           Cardano.Chain.UTxO (TxIn (..), TxOut (..))

data ByronCommand =

  --- Node Related Commands ---
    NodeCmd NodeCmd

  --- Genesis Related Commands ---
  | Genesis
        NewDirectory
        GenesisParameters
        CardanoEra
  | PrintGenesisHash
        GenesisFile

  --- Key Related Commands ---
  | Keygen
        CardanoEra
        NewSigningKeyFile
        PasswordRequirement
  | ToVerification
        CardanoEra
        SigningKeyFile
        NewVerificationKeyFile

  | PrettySigningKeyPublic
        CardanoEra
        SigningKeyFile

  | MigrateDelegateKeyFrom
        CardanoEra
        -- ^ Old CardanoEra
        SigningKeyFile
        -- ^ Old key
        CardanoEra
        -- ^ New CardanoEra
        NewSigningKeyFile
        -- ^ New Key

  | PrintSigningKeyAddress
        CardanoEra
        NetworkId
        SigningKeyFile

    --- Delegation Related Commands ---

  | IssueDelegationCertificate
        NetworkId
        CardanoEra
        EpochNumber
        -- ^ The epoch from which the delegation is valid.
        SigningKeyFile
        -- ^ The issuer of the certificate, who delegates their right to sign blocks.
        VerificationKeyFile
        -- ^ The delegate, who gains the right to sign blocks on behalf of the issuer.
        NewCertificateFile
        -- ^ Filepath of the newly created delegation certificate.
  | CheckDelegation
        NetworkId
        CertificateFile
        VerificationKeyFile
        VerificationKeyFile

  | GetLocalNodeTip
        NetworkId

    -----------------------------------

  | SubmitTx
        NetworkId
        TxFile
        -- ^ Filepath of transaction to submit.

  | SpendGenesisUTxO
        GenesisFile
        NetworkId
        CardanoEra
        NewTxFile
        -- ^ Filepath of the newly created transaction.
        SigningKeyFile
        -- ^ Signing key of genesis UTxO owner.
        Address
        -- ^ Genesis UTxO address.
        (NonEmpty TxOut)
        -- ^ Tx output.
  | SpendUTxO
        NetworkId
        CardanoEra
        NewTxFile
        -- ^ Filepath of the newly created transaction.
        SigningKeyFile
        -- ^ Signing key of Tx underwriter.
        (NonEmpty TxIn)
        -- ^ Inputs available for spending to the Tx underwriter's key.
        (NonEmpty TxOut)
        -- ^ Genesis UTxO output Address.

    --- Misc Commands ---

  | ValidateCBOR
        CBORObject
        -- ^ Type of the CBOR object
        FilePath

  | PrettyPrintCBOR
        FilePath
  deriving Int -> ByronCommand -> ShowS
[ByronCommand] -> ShowS
ByronCommand -> String
(Int -> ByronCommand -> ShowS)
-> (ByronCommand -> String)
-> ([ByronCommand] -> ShowS)
-> Show ByronCommand
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ByronCommand] -> ShowS
$cshowList :: [ByronCommand] -> ShowS
show :: ByronCommand -> String
$cshow :: ByronCommand -> String
showsPrec :: Int -> ByronCommand -> ShowS
$cshowsPrec :: Int -> ByronCommand -> ShowS
Show


data NodeCmd = CreateVote
               NetworkId
               SigningKeyFile
               FilePath -- filepath to update proposal
               Bool
               FilePath
             | UpdateProposal
               NetworkId
               SigningKeyFile
               ProtocolVersion
               SoftwareVersion
               SystemTag
               InstallerHash
               FilePath
               [ParametersToUpdate]
             | SubmitUpdateProposal
               NetworkId
               FilePath
               -- ^ Update proposal filepath.
             | SubmitVote
               NetworkId
               FilePath
               -- ^ Vote filepath.
              deriving Int -> NodeCmd -> ShowS
[NodeCmd] -> ShowS
NodeCmd -> String
(Int -> NodeCmd -> ShowS)
-> (NodeCmd -> String) -> ([NodeCmd] -> ShowS) -> Show NodeCmd
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeCmd] -> ShowS
$cshowList :: [NodeCmd] -> ShowS
show :: NodeCmd -> String
$cshow :: NodeCmd -> String
showsPrec :: Int -> NodeCmd -> ShowS
$cshowsPrec :: Int -> NodeCmd -> ShowS
Show


newtype NewCertificateFile
  = NewCertificateFile { NewCertificateFile -> String
nFp :: FilePath }
  deriving (NewCertificateFile -> NewCertificateFile -> Bool
(NewCertificateFile -> NewCertificateFile -> Bool)
-> (NewCertificateFile -> NewCertificateFile -> Bool)
-> Eq NewCertificateFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NewCertificateFile -> NewCertificateFile -> Bool
$c/= :: NewCertificateFile -> NewCertificateFile -> Bool
== :: NewCertificateFile -> NewCertificateFile -> Bool
$c== :: NewCertificateFile -> NewCertificateFile -> Bool
Eq, Int -> NewCertificateFile -> ShowS
[NewCertificateFile] -> ShowS
NewCertificateFile -> String
(Int -> NewCertificateFile -> ShowS)
-> (NewCertificateFile -> String)
-> ([NewCertificateFile] -> ShowS)
-> Show NewCertificateFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NewCertificateFile] -> ShowS
$cshowList :: [NewCertificateFile] -> ShowS
show :: NewCertificateFile -> String
$cshow :: NewCertificateFile -> String
showsPrec :: Int -> NewCertificateFile -> ShowS
$cshowsPrec :: Int -> NewCertificateFile -> ShowS
Show, String -> NewCertificateFile
(String -> NewCertificateFile) -> IsString NewCertificateFile
forall a. (String -> a) -> IsString a
fromString :: String -> NewCertificateFile
$cfromString :: String -> NewCertificateFile
IsString)