{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.Type.Error.CmdError
  ( CmdError (..)
  , renderCmdError
  )
where

import Cardano.Api

import Cardano.CLI.Render
import Cardano.CLI.Type.Error.AddressCmdError
import Cardano.CLI.Type.Error.DelegationError
import Cardano.CLI.Type.Error.GenesisCmdError
import Cardano.CLI.Type.Error.GovernanceActionsError
import Cardano.CLI.Type.Error.GovernanceCmdError
import Cardano.CLI.Type.Error.GovernanceCommitteeError
import Cardano.CLI.Type.Error.GovernanceQueryError
import Cardano.CLI.Type.Error.GovernanceVoteCmdError
import Cardano.CLI.Type.Error.KeyCmdError
import Cardano.CLI.Type.Error.NodeCmdError
import Cardano.CLI.Type.Error.QueryCmdError
import Cardano.CLI.Type.Error.RegistrationError
import Cardano.CLI.Type.Error.StakeAddressCmdError
import Cardano.CLI.Type.Error.StakePoolCmdError
import Cardano.CLI.Type.Error.TextViewFileError
import Cardano.CLI.Type.Error.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
  deriving Int -> CmdError -> ShowS
[CmdError] -> ShowS
CmdError -> String
(Int -> CmdError -> ShowS)
-> (CmdError -> String) -> ([CmdError] -> ShowS) -> Show CmdError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CmdError -> ShowS
showsPrec :: Int -> CmdError -> ShowS
$cshow :: CmdError -> String
show :: CmdError -> String
$cshowList :: [CmdError] -> ShowS
showList :: [CmdError] -> ShowS
Show

instance Error CmdError where
  prettyError :: forall ann. CmdError -> Doc ann
prettyError = \case
    CmdAddressError AddressCmdError
e -> AddressCmdError -> Doc ann
forall ann. AddressCmdError -> Doc ann
renderAddressCmdError AddressCmdError
e
    CmdEraDelegationError DelegationError
e -> 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
forall e ann. Error e => e -> Doc ann
forall ann. GenesisCmdError -> Doc ann
prettyError GenesisCmdError
e
    CmdGovernanceActionError GovernanceActionsError
e -> 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
forall e ann. Error e => e -> Doc ann
forall ann. GovernanceCmdError -> Doc ann
prettyError GovernanceCmdError
e
    CmdGovernanceCommitteeError GovernanceCommitteeError
e -> 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
forall e ann. Error e => e -> Doc ann
forall ann. GovernanceQueryError -> Doc ann
prettyError GovernanceQueryError
e
    CmdGovernanceVoteError GovernanceVoteCmdError
e -> 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
forall ann. KeyCmdError -> Doc ann
renderKeyCmdError KeyCmdError
e
    CmdNodeError NodeCmdError
e -> NodeCmdError -> Doc ann
forall ann. NodeCmdError -> Doc ann
renderNodeCmdError NodeCmdError
e
    CmdQueryError QueryCmdError
e -> QueryCmdError -> Doc ann
forall ann. QueryCmdError -> Doc ann
renderQueryCmdError QueryCmdError
e
    CmdRegistrationError RegistrationError
e -> 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
forall e ann. Error e => e -> Doc ann
forall ann. StakeAddressCmdError -> Doc ann
prettyError StakeAddressCmdError
e
    CmdStakePoolError StakePoolCmdError
e -> StakePoolCmdError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. StakePoolCmdError -> Doc ann
prettyError StakePoolCmdError
e
    CmdTextViewError TextViewFileError
e -> TextViewFileError -> Doc ann
forall ann. TextViewFileError -> Doc ann
renderTextViewFileError TextViewFileError
e
    CmdTransactionError TxCmdError
e -> TxCmdError -> Doc ann
forall ann. TxCmdError -> Doc ann
renderTxCmdError TxCmdError
e

renderCmdError :: Text -> CmdError -> Doc ann
renderCmdError :: forall ann. Text -> CmdError -> Doc ann
renderCmdError Text
cmdText = Text -> (CmdError -> Doc ann) -> CmdError -> Doc ann
forall a ann. Text -> (a -> Doc ann) -> a -> Doc ann
renderAnyCmdError Text
cmdText CmdError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. CmdError -> Doc ann
prettyError