{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.Types.Errors.CmdError
  ( CmdError (..)
  , renderCmdError
  )
where

import           Cardano.Api

import           Cardano.CLI.Render
import           Cardano.CLI.Types.Errors.AddressCmdError
import           Cardano.CLI.Types.Errors.DelegationError
import           Cardano.CLI.Types.Errors.GenesisCmdError
import           Cardano.CLI.Types.Errors.GovernanceActionsError
import           Cardano.CLI.Types.Errors.GovernanceCmdError
import           Cardano.CLI.Types.Errors.GovernanceCommitteeError
import           Cardano.CLI.Types.Errors.GovernanceQueryError
import           Cardano.CLI.Types.Errors.GovernanceVoteCmdError
import           Cardano.CLI.Types.Errors.KeyCmdError
import           Cardano.CLI.Types.Errors.NodeCmdError
import           Cardano.CLI.Types.Errors.QueryCmdError
import           Cardano.CLI.Types.Errors.RegistrationError
import           Cardano.CLI.Types.Errors.StakeAddressCmdError
import           Cardano.CLI.Types.Errors.StakePoolCmdError
import           Cardano.CLI.Types.Errors.TextViewFileError
import           Cardano.CLI.Types.Errors.TxCmdError

import           Data.Text (Text)

data CmdError
  = CmdAddressError !AddressCmdError
  | CmdEraDelegationError !DelegationError
  | CmdGenesisError !GenesisCmdError
  | CmdGovernanceActionError !GovernanceActionsError
  | CmdGovernanceCmdError !GovernanceCmdError
  | CmdGovernanceCommitteeError !GovernanceCommitteeError
  | CmdGovernanceQueryError !GovernanceQueryError
  | CmdGovernanceVoteError !GovernanceVoteCmdError
  | CmdKeyError !KeyCmdError
  | CmdNodeError !NodeCmdError
  | CmdQueryError !QueryCmdError
  | CmdRegistrationError !RegistrationError
  | CmdStakeAddressError !StakeAddressCmdError
  | CmdStakePoolError !StakePoolCmdError
  | CmdTextViewError !TextViewFileError
  | CmdTransactionError !TxCmdError

renderCmdError :: Text -> CmdError -> Doc ann
renderCmdError :: forall ann. Text -> CmdError -> Doc ann
renderCmdError Text
cmdText = \case
  CmdAddressError AddressCmdError
e -> (AddressCmdError -> Doc ann) -> AddressCmdError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError AddressCmdError -> Doc ann
forall ann. AddressCmdError -> Doc ann
renderAddressCmdError AddressCmdError
e
  CmdEraDelegationError DelegationError
e -> (DelegationError -> Doc ann) -> DelegationError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError DelegationError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. DelegationError -> Doc ann
prettyError DelegationError
e
  CmdGenesisError GenesisCmdError
e -> (GenesisCmdError -> Doc ann) -> GenesisCmdError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError GenesisCmdError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. GenesisCmdError -> Doc ann
prettyError GenesisCmdError
e
  CmdGovernanceActionError GovernanceActionsError
e -> (GovernanceActionsError -> Doc ann)
-> GovernanceActionsError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError GovernanceActionsError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. GovernanceActionsError -> Doc ann
prettyError GovernanceActionsError
e
  CmdGovernanceCmdError GovernanceCmdError
e -> (GovernanceCmdError -> Doc ann) -> GovernanceCmdError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError GovernanceCmdError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. GovernanceCmdError -> Doc ann
prettyError GovernanceCmdError
e
  CmdGovernanceCommitteeError GovernanceCommitteeError
e -> (GovernanceCommitteeError -> Doc ann)
-> GovernanceCommitteeError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError GovernanceCommitteeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. GovernanceCommitteeError -> Doc ann
prettyError GovernanceCommitteeError
e
  CmdGovernanceQueryError GovernanceQueryError
e -> (GovernanceQueryError -> Doc ann)
-> GovernanceQueryError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError GovernanceQueryError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. GovernanceQueryError -> Doc ann
prettyError GovernanceQueryError
e
  CmdGovernanceVoteError GovernanceVoteCmdError
e -> (GovernanceVoteCmdError -> Doc ann)
-> GovernanceVoteCmdError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError GovernanceVoteCmdError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. GovernanceVoteCmdError -> Doc ann
prettyError GovernanceVoteCmdError
e
  CmdKeyError KeyCmdError
e -> (KeyCmdError -> Doc ann) -> KeyCmdError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError KeyCmdError -> Doc ann
forall ann. KeyCmdError -> Doc ann
renderKeyCmdError KeyCmdError
e
  CmdNodeError NodeCmdError
e -> (NodeCmdError -> Doc ann) -> NodeCmdError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError NodeCmdError -> Doc ann
forall ann. NodeCmdError -> Doc ann
renderNodeCmdError NodeCmdError
e
  CmdQueryError QueryCmdError
e -> (QueryCmdError -> Doc ann) -> QueryCmdError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError QueryCmdError -> Doc ann
forall ann. QueryCmdError -> Doc ann
renderQueryCmdError QueryCmdError
e
  CmdRegistrationError RegistrationError
e -> (RegistrationError -> Doc ann) -> RegistrationError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError RegistrationError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. RegistrationError -> Doc ann
prettyError RegistrationError
e
  CmdStakeAddressError StakeAddressCmdError
e -> (StakeAddressCmdError -> Doc ann)
-> StakeAddressCmdError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError StakeAddressCmdError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. StakeAddressCmdError -> Doc ann
prettyError StakeAddressCmdError
e
  CmdStakePoolError StakePoolCmdError
e -> (StakePoolCmdError -> Doc ann) -> StakePoolCmdError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError StakePoolCmdError -> Doc ann
forall ann. StakePoolCmdError -> Doc ann
renderStakePoolCmdError StakePoolCmdError
e
  CmdTextViewError TextViewFileError
e -> (TextViewFileError -> Doc ann) -> TextViewFileError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError TextViewFileError -> Doc ann
forall ann. TextViewFileError -> Doc ann
renderTextViewFileError TextViewFileError
e
  CmdTransactionError TxCmdError
e -> (TxCmdError -> Doc ann) -> TxCmdError -> Doc ann
forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError TxCmdError -> Doc ann
forall ann. TxCmdError -> Doc ann
renderTxCmdError TxCmdError
e
 where
  renderError :: (a -> Doc ann) -> a -> Doc ann
  renderError :: forall a ann. (a -> Doc ann) -> a -> Doc ann
renderError = Text -> (a -> Doc ann) -> a -> Doc ann
forall a ann. Text -> (a -> Doc ann) -> a -> Doc ann
renderAnyCmdError Text
cmdText