{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.CLI.Types.Errors.AddressCmdError
  ( AddressCmdError (..)
  , renderAddressCmdError
  )
where

import           Cardano.Api

import           Cardano.CLI.Read
import           Cardano.CLI.Types.Errors.AddressInfoError
import           Cardano.CLI.Types.Key (VerificationKeyTextOrFileError (..),
                   renderVerificationKeyTextOrFileError)

data AddressCmdError
  = AddressCmdAddressInfoError !AddressInfoError
  | AddressCmdReadKeyFileError !(FileError InputDecodeError)
  | AddressCmdReadScriptFileError !(FileError ScriptDecodeError)
  | AddressCmdVerificationKeyTextOrFileError !VerificationKeyTextOrFileError
  | AddressCmdWriteFileError !(FileError ())
  | AddressCmdExpectedPaymentVerificationKey SomeAddressVerificationKey
  deriving Int -> AddressCmdError -> ShowS
[AddressCmdError] -> ShowS
AddressCmdError -> String
(Int -> AddressCmdError -> ShowS)
-> (AddressCmdError -> String)
-> ([AddressCmdError] -> ShowS)
-> Show AddressCmdError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddressCmdError -> ShowS
showsPrec :: Int -> AddressCmdError -> ShowS
$cshow :: AddressCmdError -> String
show :: AddressCmdError -> String
$cshowList :: [AddressCmdError] -> ShowS
showList :: [AddressCmdError] -> ShowS
Show

renderAddressCmdError :: AddressCmdError -> Doc ann
renderAddressCmdError :: forall ann. AddressCmdError -> Doc ann
renderAddressCmdError = \case
  AddressCmdAddressInfoError AddressInfoError
addrInfoErr ->
    AddressInfoError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. AddressInfoError -> Doc ann
prettyError AddressInfoError
addrInfoErr
  AddressCmdReadKeyFileError FileError InputDecodeError
fileErr ->
    FileError InputDecodeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError InputDecodeError -> Doc ann
prettyError FileError InputDecodeError
fileErr
  AddressCmdVerificationKeyTextOrFileError VerificationKeyTextOrFileError
vkTextOrFileErr ->
    VerificationKeyTextOrFileError -> Doc ann
forall ann. VerificationKeyTextOrFileError -> Doc ann
renderVerificationKeyTextOrFileError VerificationKeyTextOrFileError
vkTextOrFileErr
  AddressCmdReadScriptFileError FileError ScriptDecodeError
fileErr ->
    FileError ScriptDecodeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError ScriptDecodeError -> Doc ann
prettyError FileError ScriptDecodeError
fileErr
  AddressCmdWriteFileError FileError ()
fileErr ->
    FileError () -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError () -> Doc ann
prettyError FileError ()
fileErr
  AddressCmdExpectedPaymentVerificationKey SomeAddressVerificationKey
someAddress ->
    Doc ann
"Expected payment verification key but got: "
      Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (SomeAddressVerificationKey -> Text
renderSomeAddressVerificationKey SomeAddressVerificationKey
someAddress)