{- |
Module     : Agora.Effect.NoOp
Maintainer : seungheon.ooh@gmail.com
Description: Dummy dumb dumb effect.

A dumb effect that only burns its GAT.
-}
module Agora.Effect.NoOp (noOpValidator, PNoOp) where

import Control.Applicative (Const)

import Agora.Effect (makeEffect)
import Plutarch.Api.V1 (PValidator)
import Plutarch.TryFrom (PTryFrom (..))
import PlutusLedgerApi.V1.Value (CurrencySymbol)

{- | Dummy datum for NoOp effect.

     @since 0.1.0
-}
newtype PNoOp (s :: S) = PNoOp (Term s PUnit)
  deriving
    ( -- | @since 0.1.0
      PCon PNoOp
PMatch PNoOp
PCon PNoOp
-> PMatch PNoOp
-> (forall (s :: S) (b :: PType).
    PNoOp s -> Term s (PInner PNoOp b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner PNoOp b) -> (PNoOp s -> Term s b) -> Term s b)
-> PlutusType PNoOp
forall (s :: S) (b :: PType).
Term s (PInner PNoOp b) -> (PNoOp s -> Term s b) -> Term s b
forall (s :: S) (b :: PType). PNoOp s -> Term s (PInner PNoOp b)
forall (a :: PType).
PCon a
-> PMatch a
-> (forall (s :: S) (b :: PType). a s -> Term s (PInner a b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner a b) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
pmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PNoOp b) -> (PNoOp s -> Term s b) -> Term s b
$cpmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PNoOp b) -> (PNoOp s -> Term s b) -> Term s b
pcon' :: forall (s :: S) (b :: PType). PNoOp s -> Term s (PInner PNoOp b)
$cpcon' :: forall (s :: S) (b :: PType). PNoOp s -> Term s (PInner PNoOp b)
PlutusType
    , -- | @since 0.1.0
      (forall (s :: S). Term s (PAsData PNoOp) -> Term s PNoOp)
-> (forall (s :: S). Term s PNoOp -> Term s PData) -> PIsData PNoOp
forall (s :: S). Term s (PAsData PNoOp) -> Term s PNoOp
forall (s :: S). Term s PNoOp -> Term s PData
forall (a :: PType).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
pdataImpl :: forall (s :: S). Term s PNoOp -> Term s PData
$cpdataImpl :: forall (s :: S). Term s PNoOp -> Term s PData
pfromDataImpl :: forall (s :: S). Term s (PAsData PNoOp) -> Term s PNoOp
$cpfromDataImpl :: forall (s :: S). Term s (PAsData PNoOp) -> Term s PNoOp
PIsData
    )
    via (DerivePNewtype PNoOp PUnit)

-- | @since 0.1.0
instance PTryFrom PData (PAsData PNoOp) where
  type PTryFromExcess PData (PAsData PNoOp) = Const ()
  ptryFrom' :: forall (s :: S) (r :: PType).
Term s PData
-> ((Term s (PAsData PNoOp),
     Reduce @Type (PTryFromExcess PData (PAsData PNoOp) s))
    -> Term s r)
-> Term s r
ptryFrom' Term s PData
_ (Term s (PAsData PNoOp),
 Reduce @Type (PTryFromExcess PData (PAsData PNoOp) s))
-> Term s r
cont =
    -- JUSTIFICATION:
    -- We don't care anything about data.
    -- It should always be reduced to Unit.
    (Term s (PAsData PNoOp),
 Reduce @Type (PTryFromExcess PData (PAsData PNoOp) s))
-> Term s r
cont (Term s PNoOp -> Term s (PAsData PNoOp)
forall (a :: PType) (s :: S).
PIsData a =>
Term s a -> Term s (PAsData a)
pdata (Term s PNoOp -> Term s (PAsData PNoOp))
-> Term s PNoOp -> Term s (PAsData PNoOp)
forall a b. (a -> b) -> a -> b
$ PNoOp s -> Term s PNoOp
forall (a :: PType) (s :: S). PCon a => a s -> Term s a
pcon (PNoOp s -> Term s PNoOp) -> PNoOp s -> Term s PNoOp
forall a b. (a -> b) -> a -> b
$ Term s (PUnit @S) -> PNoOp s
forall (s :: S). Term s (PUnit @S) -> PNoOp s
PNoOp (PLifted (PUnit @S) -> Term s (PUnit @S)
forall (p :: PType) (s :: S). PLift p => PLifted p -> Term s p
pconstant ()), ())

{- | Dummy effect which can only burn its GAT.

     @since 0.1.0
-}
noOpValidator :: CurrencySymbol -> ClosedTerm PValidator
noOpValidator :: CurrencySymbol -> ClosedTerm PValidator
noOpValidator CurrencySymbol
curr = CurrencySymbol
-> (forall (s :: S).
    Term s PCurrencySymbol
    -> Term s PNoOp
    -> Term s PTxOutRef
    -> Term s (PAsData PTxInfo)
    -> Term s POpaque)
-> ClosedTerm PValidator
forall (datum :: PType).
(PIsData datum, PTryFrom PData (PAsData datum)) =>
CurrencySymbol
-> (forall (s :: S).
    Term s PCurrencySymbol
    -> Term s datum
    -> Term s PTxOutRef
    -> Term s (PAsData PTxInfo)
    -> Term s POpaque)
-> ClosedTerm PValidator
makeEffect CurrencySymbol
curr ((forall (s :: S).
  Term s PCurrencySymbol
  -> Term s PNoOp
  -> Term s PTxOutRef
  -> Term s (PAsData PTxInfo)
  -> Term s POpaque)
 -> ClosedTerm PValidator)
-> (forall (s :: S).
    Term s PCurrencySymbol
    -> Term s PNoOp
    -> Term s PTxOutRef
    -> Term s (PAsData PTxInfo)
    -> Term s POpaque)
-> ClosedTerm PValidator
forall a b. (a -> b) -> a -> b
$
  \Term s PCurrencySymbol
_ (Term s PNoOp
_datum :: Term s PNoOp) Term s PTxOutRef
_ Term s (PAsData PTxInfo)
_ -> Term s (PUnit @S) -> Term s POpaque
forall (s :: S) (a :: PType). Term s a -> Term s POpaque
popaque (PLifted (PUnit @S) -> Term s (PUnit @S)
forall (p :: PType) (s :: S). PLift p => PLifted p -> Term s p
pconstant ())