-- File auto generated by purescript-bridge! --
module Ledger.Tx.CardanoAPI where

import Prelude

import Control.Lazy (defer)
import Data.Argonaut (encodeJson, jsonNull)
import Data.Argonaut.Decode (class DecodeJson)
import Data.Argonaut.Decode.Aeson ((</$\>), (</*\>), (</\>))
import Data.Argonaut.Encode (class EncodeJson)
import Data.Argonaut.Encode.Aeson ((>$<), (>/\<))
import Data.Bounded.Generic (genericBottom, genericTop)
import Data.Enum (class Enum)
import Data.Enum.Generic (genericPred, genericSucc)
import Data.Generic.Rep (class Generic)
import Data.Lens (Iso', Lens', Prism', iso, prism')
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.Record (prop)
import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap)
import Data.Show.Generic (genericShow)
import Data.Tuple.Nested ((/\))
import Plutus.V1.Ledger.Tx (ScriptTag)
import Type.Proxy (Proxy(Proxy))
import Data.Argonaut.Decode.Aeson as D
import Data.Argonaut.Encode.Aeson as E
import Data.Map as Map

data FromCardanoError = SimpleScriptsNotSupported

derive instance Eq FromCardanoError

derive instance Ord FromCardanoError

instance Show FromCardanoError where
  show a = genericShow a

instance EncodeJson FromCardanoError where
  encodeJson = defer \_ -> E.encode E.enum

instance DecodeJson FromCardanoError where
  decodeJson = defer \_ -> D.decode D.enum

derive instance Generic FromCardanoError _

instance Enum FromCardanoError where
  succ = genericSucc
  pred = genericPred

instance Bounded FromCardanoError where
  bottom = genericBottom
  top = genericTop

--------------------------------------------------------------------------------

_SimpleScriptsNotSupported :: Iso' FromCardanoError Unit
_SimpleScriptsNotSupported = iso (const unit) (const SimpleScriptsNotSupported)

--------------------------------------------------------------------------------

data ToCardanoError
  = TxBodyError String
  | DeserialisationError
  | InvalidValidityRange
  | ValueNotPureAda
  | OutputHasZeroAda
  | StakingPointersNotSupported
  | SimpleScriptsNotSupportedToCardano
  | MissingTxInType
  | MissingMintingPolicyRedeemer
  | MissingMintingPolicy
  | ScriptPurposeNotSupported ScriptTag
  | Tag String ToCardanoError

derive instance Eq ToCardanoError

instance Show ToCardanoError where
  show a = genericShow a

instance EncodeJson ToCardanoError where
  encodeJson = defer \_ -> case _ of
    TxBodyError a -> E.encodeTagged "TxBodyError" a E.value
    DeserialisationError -> encodeJson { tag: "DeserialisationError", contents: jsonNull }
    InvalidValidityRange -> encodeJson { tag: "InvalidValidityRange", contents: jsonNull }
    ValueNotPureAda -> encodeJson { tag: "ValueNotPureAda", contents: jsonNull }
    OutputHasZeroAda -> encodeJson { tag: "OutputHasZeroAda", contents: jsonNull }
    StakingPointersNotSupported -> encodeJson { tag: "StakingPointersNotSupported", contents: jsonNull }
    SimpleScriptsNotSupportedToCardano -> encodeJson { tag: "SimpleScriptsNotSupportedToCardano", contents: jsonNull }
    MissingTxInType -> encodeJson { tag: "MissingTxInType", contents: jsonNull }
    MissingMintingPolicyRedeemer -> encodeJson { tag: "MissingMintingPolicyRedeemer", contents: jsonNull }
    MissingMintingPolicy -> encodeJson { tag: "MissingMintingPolicy", contents: jsonNull }
    ScriptPurposeNotSupported a -> E.encodeTagged "ScriptPurposeNotSupported" a E.value
    Tag a b -> E.encodeTagged "Tag" (a /\ b) (E.tuple (E.value >/\< E.value))

instance DecodeJson ToCardanoError where
  decodeJson = defer \_ -> D.decode
    $ D.sumType "ToCardanoError"
    $ Map.fromFoldable
        [ "TxBodyError" /\ D.content (TxBodyError <$> D.value)
        , "DeserialisationError" /\ pure DeserialisationError
        , "InvalidValidityRange" /\ pure InvalidValidityRange
        , "ValueNotPureAda" /\ pure ValueNotPureAda
        , "OutputHasZeroAda" /\ pure OutputHasZeroAda
        , "StakingPointersNotSupported" /\ pure StakingPointersNotSupported
        , "SimpleScriptsNotSupportedToCardano" /\ pure SimpleScriptsNotSupportedToCardano
        , "MissingTxInType" /\ pure MissingTxInType
        , "MissingMintingPolicyRedeemer" /\ pure MissingMintingPolicyRedeemer
        , "MissingMintingPolicy" /\ pure MissingMintingPolicy
        , "ScriptPurposeNotSupported" /\ D.content (ScriptPurposeNotSupported <$> D.value)
        , "Tag" /\ D.content (D.tuple $ Tag </$\> D.value </*\> D.value)
        ]

derive instance Generic ToCardanoError _

--------------------------------------------------------------------------------

_TxBodyError :: Prism' ToCardanoError String
_TxBodyError = prism' TxBodyError case _ of
  (TxBodyError a) -> Just a
  _ -> Nothing

_DeserialisationError :: Prism' ToCardanoError Unit
_DeserialisationError = prism' (const DeserialisationError) case _ of
  DeserialisationError -> Just unit
  _ -> Nothing

_InvalidValidityRange :: Prism' ToCardanoError Unit
_InvalidValidityRange = prism' (const InvalidValidityRange) case _ of
  InvalidValidityRange -> Just unit
  _ -> Nothing

_ValueNotPureAda :: Prism' ToCardanoError Unit
_ValueNotPureAda = prism' (const ValueNotPureAda) case _ of
  ValueNotPureAda -> Just unit
  _ -> Nothing

_OutputHasZeroAda :: Prism' ToCardanoError Unit
_OutputHasZeroAda = prism' (const OutputHasZeroAda) case _ of
  OutputHasZeroAda -> Just unit
  _ -> Nothing

_StakingPointersNotSupported :: Prism' ToCardanoError Unit
_StakingPointersNotSupported = prism' (const StakingPointersNotSupported) case _ of
  StakingPointersNotSupported -> Just unit
  _ -> Nothing

_SimpleScriptsNotSupportedToCardano :: Prism' ToCardanoError Unit
_SimpleScriptsNotSupportedToCardano = prism' (const SimpleScriptsNotSupportedToCardano) case _ of
  SimpleScriptsNotSupportedToCardano -> Just unit
  _ -> Nothing

_MissingTxInType :: Prism' ToCardanoError Unit
_MissingTxInType = prism' (const MissingTxInType) case _ of
  MissingTxInType -> Just unit
  _ -> Nothing

_MissingMintingPolicyRedeemer :: Prism' ToCardanoError Unit
_MissingMintingPolicyRedeemer = prism' (const MissingMintingPolicyRedeemer) case _ of
  MissingMintingPolicyRedeemer -> Just unit
  _ -> Nothing

_MissingMintingPolicy :: Prism' ToCardanoError Unit
_MissingMintingPolicy = prism' (const MissingMintingPolicy) case _ of
  MissingMintingPolicy -> Just unit
  _ -> Nothing

_ScriptPurposeNotSupported :: Prism' ToCardanoError ScriptTag
_ScriptPurposeNotSupported = prism' ScriptPurposeNotSupported case _ of
  (ScriptPurposeNotSupported a) -> Just a
  _ -> Nothing

_Tag :: Prism' ToCardanoError { a :: String, b :: ToCardanoError }
_Tag = prism' (\{ a, b } -> (Tag a b)) case _ of
  (Tag a b) -> Just { a, b }
  _ -> Nothing
