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

module Cardano.CLI.EraBased.Commands.Governance.DRep
  ( GovernanceDRepCmds (..)
  , renderGovernanceDRepCmds
  , GovernanceDRepKeyGenCmdArgs (..)
  , GovernanceDRepIdCmdArgs (..)
  , GovernanceDRepRegistrationCertificateCmdArgs (..)
  , GovernanceDRepRetirementCertificateCmdArgs (..)
  , GovernanceDRepUpdateCertificateCmdArgs (..)
  , GovernanceDRepMetadataHashCmdArgs (..)
  , DRepMetadataSource (..)
  )
where

import           Cardano.Api
import qualified Cardano.Api.Ledger as L

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

import           Data.Text (Text)

data GovernanceDRepCmds era
  = GovernanceDRepKeyGenCmd !(GovernanceDRepKeyGenCmdArgs era)
  | GovernanceDRepIdCmd !(GovernanceDRepIdCmdArgs era)
  | GovernanceDRepRegistrationCertificateCmd !(GovernanceDRepRegistrationCertificateCmdArgs era)
  | GovernanceDRepRetirementCertificateCmd !(GovernanceDRepRetirementCertificateCmdArgs era)
  | GovernanceDRepUpdateCertificateCmd !(GovernanceDRepUpdateCertificateCmdArgs era)
  | GovernanceDRepMetadataHashCmd !(GovernanceDRepMetadataHashCmdArgs era)

data GovernanceDRepKeyGenCmdArgs era
  = GovernanceDRepKeyGenCmdArgs
  { forall era. GovernanceDRepKeyGenCmdArgs era -> ConwayEraOnwards era
eon :: !(ConwayEraOnwards era)
  , forall era.
GovernanceDRepKeyGenCmdArgs era -> File (VerificationKey ()) 'Out
vkeyFile :: !(File (VerificationKey ()) Out)
  , forall era.
GovernanceDRepKeyGenCmdArgs era -> File (SigningKey ()) 'Out
skeyFile :: !(File (SigningKey ()) Out)
  }

data GovernanceDRepIdCmdArgs era
  = GovernanceDRepIdCmdArgs
  { forall era. GovernanceDRepIdCmdArgs era -> ConwayEraOnwards era
eon :: !(ConwayEraOnwards era)
  , forall era.
GovernanceDRepIdCmdArgs era -> VerificationKeyOrFile DRepKey
vkeySource :: !(VerificationKeyOrFile DRepKey)
  , forall era. GovernanceDRepIdCmdArgs era -> IdOutputFormat
idOutputFormat :: !IdOutputFormat
  , forall era. GovernanceDRepIdCmdArgs era -> Maybe (File () 'Out)
mOutFile :: !(Maybe (File () Out))
  }

data GovernanceDRepRegistrationCertificateCmdArgs era
  = GovernanceDRepRegistrationCertificateCmdArgs
  { forall era.
GovernanceDRepRegistrationCertificateCmdArgs era
-> ConwayEraOnwards era
eon :: !(ConwayEraOnwards era)
  , forall era.
GovernanceDRepRegistrationCertificateCmdArgs era -> DRepHashSource
drepHashSource :: !DRepHashSource
  , forall era.
GovernanceDRepRegistrationCertificateCmdArgs era -> Lovelace
deposit :: !Lovelace
  , forall era.
GovernanceDRepRegistrationCertificateCmdArgs era
-> Maybe
     (PotentiallyCheckedAnchor DRepMetadataUrl (Anchor StandardCrypto))
mAnchor
      :: !( Maybe
              ( PotentiallyCheckedAnchor
                  DRepMetadataUrl
                  (L.Anchor L.StandardCrypto)
              )
          )
  , forall era.
GovernanceDRepRegistrationCertificateCmdArgs era -> File () 'Out
outFile :: !(File () Out)
  }

data GovernanceDRepRetirementCertificateCmdArgs era
  = GovernanceDRepRetirementCertificateCmdArgs
  { forall era.
GovernanceDRepRetirementCertificateCmdArgs era
-> ConwayEraOnwards era
eon :: !(ConwayEraOnwards era)
  , forall era.
GovernanceDRepRetirementCertificateCmdArgs era -> DRepHashSource
drepHashSource :: !DRepHashSource
  , forall era.
GovernanceDRepRetirementCertificateCmdArgs era -> Lovelace
deposit :: !Lovelace
  , forall era.
GovernanceDRepRetirementCertificateCmdArgs era -> File () 'Out
outFile :: !(File () Out)
  }

data GovernanceDRepUpdateCertificateCmdArgs era
  = GovernanceDRepUpdateCertificateCmdArgs
  { forall era.
GovernanceDRepUpdateCertificateCmdArgs era -> ConwayEraOnwards era
eon :: !(ConwayEraOnwards era)
  , forall era.
GovernanceDRepUpdateCertificateCmdArgs era -> DRepHashSource
drepHashSource :: !DRepHashSource
  , forall era.
GovernanceDRepUpdateCertificateCmdArgs era
-> Maybe
     (PotentiallyCheckedAnchor DRepMetadataUrl (Anchor StandardCrypto))
mAnchor
      :: Maybe
          ( PotentiallyCheckedAnchor
              DRepMetadataUrl
              (L.Anchor L.StandardCrypto)
          )
  , forall era.
GovernanceDRepUpdateCertificateCmdArgs era -> File () 'Out
outFile :: !(File () Out)
  }

data GovernanceDRepMetadataHashCmdArgs era
  = GovernanceDRepMetadataHashCmdArgs
  { forall era.
GovernanceDRepMetadataHashCmdArgs era -> ConwayEraOnwards era
eon :: !(ConwayEraOnwards era)
  , forall era.
GovernanceDRepMetadataHashCmdArgs era -> DRepMetadataSource
drepMetadataSource :: !DRepMetadataSource
  , forall era.
GovernanceDRepMetadataHashCmdArgs era
-> HashGoal (Hash DRepMetadata)
hashGoal :: !(HashGoal (Hash DRepMetadata))
  }

data DRepMetadataSource
  = DrepMetadataFileIn !(DRepMetadataFile In)
  | DrepMetadataURL !L.Url
  deriving Int -> DRepMetadataSource -> ShowS
[DRepMetadataSource] -> ShowS
DRepMetadataSource -> String
(Int -> DRepMetadataSource -> ShowS)
-> (DRepMetadataSource -> String)
-> ([DRepMetadataSource] -> ShowS)
-> Show DRepMetadataSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DRepMetadataSource -> ShowS
showsPrec :: Int -> DRepMetadataSource -> ShowS
$cshow :: DRepMetadataSource -> String
show :: DRepMetadataSource -> String
$cshowList :: [DRepMetadataSource] -> ShowS
showList :: [DRepMetadataSource] -> ShowS
Show

renderGovernanceDRepCmds
  :: ()
  => GovernanceDRepCmds era
  -> Text
renderGovernanceDRepCmds :: forall era. GovernanceDRepCmds era -> Text
renderGovernanceDRepCmds = \case
  GovernanceDRepKeyGenCmd{} ->
    Text
"governance drep key-gen"
  GovernanceDRepIdCmd{} ->
    Text
"governance drep id"
  GovernanceDRepRegistrationCertificateCmd{} ->
    Text
"governance drep registration-certificate"
  GovernanceDRepRetirementCertificateCmd{} ->
    Text
"governance drep retirement-certificate"
  GovernanceDRepUpdateCertificateCmd{} ->
    Text
"governance drep update-certificate"
  GovernanceDRepMetadataHashCmd{} ->
    Text
"governance drep metadata-hash"