{-# OPTIONS_GHC -Wno-orphans #-}

module PlutusLedgerApi.V1.Orphans (
  UnsortedAssocMap,
  getUnsortedAssocMap,
  MintValue,
  getMintValue,
  UTxOValue,
  getUtxoValue,
) where

import PlutusLedgerApi.Orphans.Common (UnsortedAssocMap, getUnsortedAssocMap)
import PlutusLedgerApi.V1 qualified as PLA
import PlutusLedgerApi.V1.Orphans.Address ()
import PlutusLedgerApi.V1.Orphans.Contexts ()
import PlutusLedgerApi.V1.Orphans.Credential ()
import PlutusLedgerApi.V1.Orphans.Crypto ()
import PlutusLedgerApi.V1.Orphans.DCert ()
import PlutusLedgerApi.V1.Orphans.Interval ()
import PlutusLedgerApi.V1.Orphans.Scripts ()
import PlutusLedgerApi.V1.Orphans.Time ()
import PlutusLedgerApi.V1.Orphans.Tx ()
import PlutusLedgerApi.V1.Orphans.Value (MintValue, UTxOValue, getMintValue, getUtxoValue)
import Test.QuickCheck (
  Arbitrary (arbitrary, shrink),
  CoArbitrary (coarbitrary),
  Function (function),
  functionMap,
 )

-- | @since 1.0.2
instance Arbitrary PLA.ScriptContext where
  {-# INLINEABLE arbitrary #-}
  arbitrary :: Gen ScriptContext
arbitrary = TxInfo -> ScriptPurpose -> ScriptContext
PLA.ScriptContext (TxInfo -> ScriptPurpose -> ScriptContext)
-> Gen TxInfo -> Gen (ScriptPurpose -> ScriptContext)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen TxInfo
forall a. Arbitrary a => Gen a
arbitrary Gen (ScriptPurpose -> ScriptContext)
-> Gen ScriptPurpose -> Gen ScriptContext
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Gen ScriptPurpose
forall a. Arbitrary a => Gen a
arbitrary
  {-# INLINEABLE shrink #-}
  shrink :: ScriptContext -> [ScriptContext]
shrink (PLA.ScriptContext TxInfo
tinfo ScriptPurpose
p) =
    TxInfo -> ScriptPurpose -> ScriptContext
PLA.ScriptContext (TxInfo -> ScriptPurpose -> ScriptContext)
-> [TxInfo] -> [ScriptPurpose -> ScriptContext]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> TxInfo -> [TxInfo]
forall a. Arbitrary a => a -> [a]
shrink TxInfo
tinfo [ScriptPurpose -> ScriptContext]
-> [ScriptPurpose] -> [ScriptContext]
forall a b. [a -> b] -> [a] -> [b]
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> ScriptPurpose -> [ScriptPurpose]
forall a. Arbitrary a => a -> [a]
shrink ScriptPurpose
p

-- | @since 1.0.2
instance CoArbitrary PLA.ScriptContext where
  {-# INLINEABLE coarbitrary #-}
  coarbitrary :: forall b. ScriptContext -> Gen b -> Gen b
coarbitrary (PLA.ScriptContext TxInfo
tinfo ScriptPurpose
p) =
    TxInfo -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
forall b. TxInfo -> Gen b -> Gen b
coarbitrary TxInfo
tinfo (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScriptPurpose -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
forall b. ScriptPurpose -> Gen b -> Gen b
coarbitrary ScriptPurpose
p

-- | @since 1.0.2
instance Function PLA.ScriptContext where
  {-# INLINEABLE function #-}
  function :: forall b. (ScriptContext -> b) -> ScriptContext :-> b
function =
    (ScriptContext -> (TxInfo, ScriptPurpose))
-> ((TxInfo, ScriptPurpose) -> ScriptContext)
-> (ScriptContext -> b)
-> ScriptContext :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap
      (\(PLA.ScriptContext TxInfo
tinfo ScriptPurpose
p) -> (TxInfo
tinfo, ScriptPurpose
p))
      ((TxInfo -> ScriptPurpose -> ScriptContext)
-> (TxInfo, ScriptPurpose) -> ScriptContext
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry TxInfo -> ScriptPurpose -> ScriptContext
PLA.ScriptContext)