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

module Cardano.CLI.Types.Errors.DelegationError
  ( DelegationError (..)
  )
where

import           Cardano.Api

import           Cardano.CLI.Types.Errors.StakeCredentialError

import           GHC.Generics (Generic)

data DelegationError
  = DelegationReadError !(FileError InputDecodeError)
  | DelegationCertificateWriteFileError !(FileError ())
  | DelegationDRepReadError !(FileError InputDecodeError)
  | DelegationStakeCredentialError !StakeCredentialError
  deriving (Int -> DelegationError -> ShowS
[DelegationError] -> ShowS
DelegationError -> String
(Int -> DelegationError -> ShowS)
-> (DelegationError -> String)
-> ([DelegationError] -> ShowS)
-> Show DelegationError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DelegationError -> ShowS
showsPrec :: Int -> DelegationError -> ShowS
$cshow :: DelegationError -> String
show :: DelegationError -> String
$cshowList :: [DelegationError] -> ShowS
showList :: [DelegationError] -> ShowS
Show, (forall x. DelegationError -> Rep DelegationError x)
-> (forall x. Rep DelegationError x -> DelegationError)
-> Generic DelegationError
forall x. Rep DelegationError x -> DelegationError
forall x. DelegationError -> Rep DelegationError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DelegationError -> Rep DelegationError x
from :: forall x. DelegationError -> Rep DelegationError x
$cto :: forall x. Rep DelegationError x -> DelegationError
to :: forall x. Rep DelegationError x -> DelegationError
Generic)

instance Error DelegationError where
  prettyError :: forall ann. DelegationError -> Doc ann
prettyError = \case
    DelegationReadError FileError InputDecodeError
e ->
      Doc ann
"Cannot read delegation target: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> FileError InputDecodeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError InputDecodeError -> Doc ann
prettyError FileError InputDecodeError
e
    DelegationStakeCredentialError StakeCredentialError
e ->
      Doc ann
"Cannot get stake credential: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> StakeCredentialError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. StakeCredentialError -> Doc ann
prettyError StakeCredentialError
e
    DelegationCertificateWriteFileError FileError ()
e ->
      Doc ann
"Cannot write certificate: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> FileError () -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError () -> Doc ann
prettyError FileError ()
e
    DelegationDRepReadError FileError InputDecodeError
e ->
      Doc ann
"Cannot read DRep key: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> FileError InputDecodeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError InputDecodeError -> Doc ann
prettyError FileError InputDecodeError
e