module Hydra.Contract.HeadError (
  errorCode,
  module Hydra.Contract.HeadError,
) where

import Hydra.Contract.Error (ToErrorCode (..), errorCode)

data HeadError
  = InvalidHeadStateTransition
  | ChangedParameters
  | WrongStateInOutputDatum
  | HeadValueIsNotPreserved
  | SignerIsNotAParticipant
  | NoSigners
  | TooManySigners
  | ScriptNotSpendingAHeadInput
  | NoOutputDatumError
  | UnexpectedNonInlineDatum
  | NotPayingToHead
  | SignatureVerificationFailed
  | MustNotChangeVersion
  | BurntTokenNumberMismatch
  | ReimbursedOutputsDontMatch
  | STNotSpent
  | IncorrectUtxoHash
  | MissingCommits
  | NotAllValueCollected
  | IncorrectVersion
  | VersionNotIncremented
  | HasBoundedValidityCheckFailed
  | IncorrectClosedContestationDeadline
  | InfiniteUpperBound
  | InfiniteLowerBound
  | ContestersNonEmpty
  | CloseNoUpperBoundDefined
  | FailedCloseInitial
  | FailedCloseCurrent
  | FailedCloseOutdated
  | TooOldSnapshot
  | UpperBoundBeyondContestationDeadline
  | ContestNoUpperBoundDefined
  | MustNotPushDeadline
  | MustPushDeadline
  | ContesterNotIncluded
  | WrongNumberOfSigners
  | SignerAlreadyContested
  | FailedContestCurrent
  | FailedContestOutdated
  | FanoutUTxOHashMismatch
  | LowerBoundBeforeContestationDeadline
  | FanoutNoLowerBoundDefined
  | FanoutUTxOToDecommitHashMismatch

instance ToErrorCode HeadError where
  toErrorCode :: HeadError -> Text
toErrorCode = \case
    -- Generic
    HeadError
InvalidHeadStateTransition -> Text
"H1"
    HeadError
ChangedParameters -> Text
"H2"
    HeadError
WrongStateInOutputDatum -> Text
"H3"
    HeadError
HeadValueIsNotPreserved -> Text
"H4"
    HeadError
SignerIsNotAParticipant -> Text
"H5"
    HeadError
NoSigners -> Text
"H6"
    HeadError
TooManySigners -> Text
"H7"
    HeadError
ScriptNotSpendingAHeadInput -> Text
"H8"
    HeadError
NoOutputDatumError -> Text
"H9"
    HeadError
UnexpectedNonInlineDatum -> Text
"H10"
    HeadError
NotPayingToHead -> Text
"H11"
    HeadError
SignatureVerificationFailed -> Text
"H12"
    HeadError
MustNotChangeVersion -> Text
"H13"
    -- Abort
    HeadError
BurntTokenNumberMismatch -> Text
"H14"
    HeadError
ReimbursedOutputsDontMatch -> Text
"H15"
    -- Collect
    HeadError
STNotSpent -> Text
"H16"
    HeadError
IncorrectUtxoHash -> Text
"H17"
    HeadError
MissingCommits -> Text
"H18"
    HeadError
NotAllValueCollected -> Text
"H19"
    HeadError
IncorrectVersion -> Text
"H20"
    -- Decrement
    HeadError
VersionNotIncremented -> Text
"H21"
    -- Close
    HeadError
HasBoundedValidityCheckFailed -> Text
"H22"
    HeadError
IncorrectClosedContestationDeadline -> Text
"H23"
    HeadError
InfiniteUpperBound -> Text
"H24"
    HeadError
InfiniteLowerBound -> Text
"H25"
    HeadError
ContestersNonEmpty -> Text
"H26"
    HeadError
CloseNoUpperBoundDefined -> Text
"H27"
    HeadError
FailedCloseInitial -> Text
"H28"
    HeadError
FailedCloseCurrent -> Text
"H29"
    HeadError
FailedCloseOutdated -> Text
"H30"
    -- Contest
    HeadError
TooOldSnapshot -> Text
"H31"
    HeadError
UpperBoundBeyondContestationDeadline -> Text
"H32"
    HeadError
ContestNoUpperBoundDefined -> Text
"H33"
    HeadError
MustNotPushDeadline -> Text
"H34"
    HeadError
MustPushDeadline -> Text
"H35"
    HeadError
ContesterNotIncluded -> Text
"H36"
    HeadError
WrongNumberOfSigners -> Text
"H37"
    HeadError
SignerAlreadyContested -> Text
"H38"
    HeadError
FailedContestCurrent -> Text
"H39"
    HeadError
FailedContestOutdated -> Text
"H40"
    -- Fanout
    HeadError
FanoutUTxOHashMismatch -> Text
"H41"
    HeadError
FanoutUTxOToDecommitHashMismatch -> Text
"H42"
    HeadError
LowerBoundBeforeContestationDeadline -> Text
"H43"
    HeadError
FanoutNoLowerBoundDefined -> Text
"H44"