-- SPDX-FileCopyrightText: 2022 Oxhead Alpha
-- SPDX-License-Identifier: LicenseRef-MIT-OA

{-# OPTIONS_GHC -Wno-orphans #-}

-- | Definitions for calling @txr1@ addresses
module Lorentz.Txr1Call
  ( Txr1CallParam
  ) where

import Lorentz.Annotation
import Lorentz.Constraints.Scopes
import Lorentz.Entrypoints
import Lorentz.Value
import Morley.Tezos.Address

-- | Call parameter for @txr1@ addresses. Default entrypoint doesn't exist, but
-- here we simply represent it as having @never@ parameter, thus uncallable.
data Txr1CallParam a = Deposit (Ticket a, TxRollupL2Address) | Default Never
  deriving stock (forall x. Txr1CallParam a -> Rep (Txr1CallParam a) x)
-> (forall x. Rep (Txr1CallParam a) x -> Txr1CallParam a)
-> Generic (Txr1CallParam a)
forall x. Rep (Txr1CallParam a) x -> Txr1CallParam a
forall x. Txr1CallParam a -> Rep (Txr1CallParam a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Txr1CallParam a) x -> Txr1CallParam a
forall a x. Txr1CallParam a -> Rep (Txr1CallParam a) x
$cto :: forall a x. Rep (Txr1CallParam a) x -> Txr1CallParam a
$cfrom :: forall a x. Txr1CallParam a -> Rep (Txr1CallParam a) x
Generic
  deriving anyclass (AnnOptions
FollowEntrypointFlag -> Notes (ToT (Txr1CallParam a))
(FollowEntrypointFlag -> Notes (ToT (Txr1CallParam a)))
-> AnnOptions -> HasAnnotation (Txr1CallParam a)
forall a. HasAnnotation a => AnnOptions
forall a.
HasAnnotation a =>
FollowEntrypointFlag -> Notes (ToT (Txr1CallParam a))
forall a.
(FollowEntrypointFlag -> Notes (ToT a))
-> AnnOptions -> HasAnnotation a
annOptions :: AnnOptions
$cannOptions :: forall a. HasAnnotation a => AnnOptions
getAnnotation :: FollowEntrypointFlag -> Notes (ToT (Txr1CallParam a))
$cgetAnnotation :: forall a.
HasAnnotation a =>
FollowEntrypointFlag -> Notes (ToT (Txr1CallParam a))
HasAnnotation)

instance NiceComparable a => IsoValue (Txr1CallParam a)

instance (HasAnnotation a, NiceComparable a) => ParameterHasEntrypoints (Txr1CallParam a) where
  type ParameterEntrypointsDerivation (Txr1CallParam a) = EpdPlain

-- NB: This is an orphan, because otherwise we have nasty circular dependencies between modules
instance (cp ~ Txr1CallParam a, vd ~ ()) => ToTAddress cp vd TxRollupAddress where
  toTAddress :: TxRollupAddress -> TAddress cp vd
toTAddress = Address -> TAddress cp vd
forall p vd. Address -> TAddress p vd
TAddress (Address -> TAddress cp vd)
-> (TxRollupAddress -> Address)
-> TxRollupAddress
-> TAddress cp vd
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxRollupAddress -> Address
forall (kind :: AddressKind). KindedAddress kind -> Address
MkAddress