{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Commands.TopLevelCommands
  ( AnyEraCommand (..)
  , Cmds (..)
  , renderAnyEraCommand
  , renderCmds
  )
where

import           Cardano.Api (ShelleyBasedEra (..))

import           Cardano.CLI.Commands.Address
import           Cardano.CLI.Commands.Key
import           Cardano.CLI.Commands.Node
import           Cardano.CLI.EraBased.Commands.Genesis
import           Cardano.CLI.EraBased.Commands.Query
import           Cardano.CLI.EraBased.Commands.StakeAddress
import           Cardano.CLI.EraBased.Commands.StakePool
import           Cardano.CLI.EraBased.Commands.TextView
import           Cardano.CLI.EraBased.Commands.Transaction
import           Cardano.CLI.EraBased.Options.Governance (GovernanceCmds, renderGovernanceCmds)

import           Data.Text (Text)
import           Data.Typeable (Typeable)

data AnyEraCommand where
  AnyEraCommandOf :: Typeable era => ShelleyBasedEra era -> Cmds era -> AnyEraCommand

renderAnyEraCommand :: AnyEraCommand -> Text
renderAnyEraCommand :: AnyEraCommand -> Text
renderAnyEraCommand = \case
  AnyEraCommandOf ShelleyBasedEra era
_ Cmds era
cmd -> Cmds era -> Text
forall era. Cmds era -> Text
renderCmds Cmds era
cmd

data Cmds era
  = AddressCmds AddressCmds
  | KeyCmds KeyCmds
  | GenesisCmds (GenesisCmds era)
  | GovernanceCmds (GovernanceCmds era)
  | NodeCmds NodeCmds
  | QueryCmds (QueryCmds era)
  | StakeAddressCmds (StakeAddressCmds era)
  | StakePoolCmds (StakePoolCmds era)
  | TextViewCmds (TextViewCmds era)
  | TransactionCmds (TransactionCmds era)

renderCmds :: Cmds era -> Text
renderCmds :: forall era. Cmds era -> Text
renderCmds = \case
  AddressCmds AddressCmds
cmd ->
    AddressCmds -> Text
renderAddressCmds AddressCmds
cmd
  KeyCmds KeyCmds
cmd ->
    KeyCmds -> Text
renderKeyCmds KeyCmds
cmd
  GenesisCmds GenesisCmds era
cmd ->
    GenesisCmds era -> Text
forall era. GenesisCmds era -> Text
renderGenesisCmds GenesisCmds era
cmd
  GovernanceCmds GovernanceCmds era
cmd ->
    GovernanceCmds era -> Text
forall era. GovernanceCmds era -> Text
renderGovernanceCmds GovernanceCmds era
cmd
  NodeCmds NodeCmds
cmd ->
    NodeCmds -> Text
renderNodeCmds NodeCmds
cmd
  QueryCmds QueryCmds era
cmd ->
    QueryCmds era -> Text
forall era. QueryCmds era -> Text
renderQueryCmds QueryCmds era
cmd
  StakeAddressCmds StakeAddressCmds era
cmd ->
    StakeAddressCmds era -> Text
forall era. StakeAddressCmds era -> Text
renderStakeAddressCmds StakeAddressCmds era
cmd
  StakePoolCmds StakePoolCmds era
cmd ->
    StakePoolCmds era -> Text
forall era. StakePoolCmds era -> Text
renderStakePoolCmds StakePoolCmds era
cmd
  TextViewCmds TextViewCmds era
cmd ->
    TextViewCmds era -> Text
forall era. TextViewCmds era -> Text
renderTextViewCmds TextViewCmds era
cmd
  TransactionCmds TransactionCmds era
cmd ->
    TransactionCmds era -> Text
forall era. TransactionCmds era -> Text
renderTransactionCmds TransactionCmds era
cmd