{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}

module Cardano.CLI.EraBased.Script.Proposal.Type
  ( CliProposalScriptRequirements (..)
  , PlutusRefScriptCliArgs (..)
  , PlutusScriptCliArgs (..)
  , ProposalScriptWitness (..)
  , createSimpleOrPlutusScriptFromCliArgs
  , createPlutusReferenceScriptFromCliArgs
  )
where

import Cardano.Api

import Cardano.CLI.Type.Common (ScriptDataOrFile)

newtype ProposalScriptWitness era
  = ProposalScriptWitness {forall era.
ProposalScriptWitness era -> ScriptWitness WitCtxStake era
pswScriptWitness :: ScriptWitness WitCtxStake era}
  deriving Int -> ProposalScriptWitness era -> ShowS
[ProposalScriptWitness era] -> ShowS
ProposalScriptWitness era -> String
(Int -> ProposalScriptWitness era -> ShowS)
-> (ProposalScriptWitness era -> String)
-> ([ProposalScriptWitness era] -> ShowS)
-> Show (ProposalScriptWitness era)
forall era. Int -> ProposalScriptWitness era -> ShowS
forall era. [ProposalScriptWitness era] -> ShowS
forall era. ProposalScriptWitness era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall era. Int -> ProposalScriptWitness era -> ShowS
showsPrec :: Int -> ProposalScriptWitness era -> ShowS
$cshow :: forall era. ProposalScriptWitness era -> String
show :: ProposalScriptWitness era -> String
$cshowList :: forall era. [ProposalScriptWitness era] -> ShowS
showList :: [ProposalScriptWitness era] -> ShowS
Show

data CliProposalScriptRequirements
  = OnDiskPlutusScript PlutusScriptCliArgs
  | OnDiskSimpleScript (File ScriptInAnyLang In)
  | OnDiskPlutusRefScript PlutusRefScriptCliArgs
  deriving Int -> CliProposalScriptRequirements -> ShowS
[CliProposalScriptRequirements] -> ShowS
CliProposalScriptRequirements -> String
(Int -> CliProposalScriptRequirements -> ShowS)
-> (CliProposalScriptRequirements -> String)
-> ([CliProposalScriptRequirements] -> ShowS)
-> Show CliProposalScriptRequirements
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CliProposalScriptRequirements -> ShowS
showsPrec :: Int -> CliProposalScriptRequirements -> ShowS
$cshow :: CliProposalScriptRequirements -> String
show :: CliProposalScriptRequirements -> String
$cshowList :: [CliProposalScriptRequirements] -> ShowS
showList :: [CliProposalScriptRequirements] -> ShowS
Show

data PlutusScriptCliArgs
  = OnDiskPlutusScriptCliArgs
      (File ScriptInAnyLang In)
      ScriptDataOrFile
      -- ^ Redeemer
      ExecutionUnits
  deriving Int -> PlutusScriptCliArgs -> ShowS
[PlutusScriptCliArgs] -> ShowS
PlutusScriptCliArgs -> String
(Int -> PlutusScriptCliArgs -> ShowS)
-> (PlutusScriptCliArgs -> String)
-> ([PlutusScriptCliArgs] -> ShowS)
-> Show PlutusScriptCliArgs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PlutusScriptCliArgs -> ShowS
showsPrec :: Int -> PlutusScriptCliArgs -> ShowS
$cshow :: PlutusScriptCliArgs -> String
show :: PlutusScriptCliArgs -> String
$cshowList :: [PlutusScriptCliArgs] -> ShowS
showList :: [PlutusScriptCliArgs] -> ShowS
Show

createSimpleOrPlutusScriptFromCliArgs
  :: File ScriptInAnyLang In
  -> Maybe (ScriptDataOrFile, ExecutionUnits)
  -> CliProposalScriptRequirements
createSimpleOrPlutusScriptFromCliArgs :: File ScriptInAnyLang 'In
-> Maybe (ScriptDataOrFile, ExecutionUnits)
-> CliProposalScriptRequirements
createSimpleOrPlutusScriptFromCliArgs File ScriptInAnyLang 'In
scriptFp (Just (ScriptDataOrFile
redeemer, ExecutionUnits
execUnits)) =
  PlutusScriptCliArgs -> CliProposalScriptRequirements
OnDiskPlutusScript (PlutusScriptCliArgs -> CliProposalScriptRequirements)
-> PlutusScriptCliArgs -> CliProposalScriptRequirements
forall a b. (a -> b) -> a -> b
$ File ScriptInAnyLang 'In
-> ScriptDataOrFile -> ExecutionUnits -> PlutusScriptCliArgs
OnDiskPlutusScriptCliArgs File ScriptInAnyLang 'In
scriptFp ScriptDataOrFile
redeemer ExecutionUnits
execUnits
createSimpleOrPlutusScriptFromCliArgs File ScriptInAnyLang 'In
scriptFp Maybe (ScriptDataOrFile, ExecutionUnits)
Nothing =
  File ScriptInAnyLang 'In -> CliProposalScriptRequirements
OnDiskSimpleScript File ScriptInAnyLang 'In
scriptFp

data PlutusRefScriptCliArgs
  = PlutusRefScriptCliArgs
      TxIn
      -- ^ TxIn with reference script
      AnyPlutusScriptVersion
      ScriptDataOrFile
      -- ^ Redeemer
      ExecutionUnits
  deriving Int -> PlutusRefScriptCliArgs -> ShowS
[PlutusRefScriptCliArgs] -> ShowS
PlutusRefScriptCliArgs -> String
(Int -> PlutusRefScriptCliArgs -> ShowS)
-> (PlutusRefScriptCliArgs -> String)
-> ([PlutusRefScriptCliArgs] -> ShowS)
-> Show PlutusRefScriptCliArgs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PlutusRefScriptCliArgs -> ShowS
showsPrec :: Int -> PlutusRefScriptCliArgs -> ShowS
$cshow :: PlutusRefScriptCliArgs -> String
show :: PlutusRefScriptCliArgs -> String
$cshowList :: [PlutusRefScriptCliArgs] -> ShowS
showList :: [PlutusRefScriptCliArgs] -> ShowS
Show

createPlutusReferenceScriptFromCliArgs
  :: TxIn
  -> AnyPlutusScriptVersion
  -> ScriptDataOrFile
  -> ExecutionUnits
  -> CliProposalScriptRequirements
createPlutusReferenceScriptFromCliArgs :: TxIn
-> AnyPlutusScriptVersion
-> ScriptDataOrFile
-> ExecutionUnits
-> CliProposalScriptRequirements
createPlutusReferenceScriptFromCliArgs TxIn
txIn AnyPlutusScriptVersion
version ScriptDataOrFile
redeemer ExecutionUnits
execUnits =
  PlutusRefScriptCliArgs -> CliProposalScriptRequirements
OnDiskPlutusRefScript (PlutusRefScriptCliArgs -> CliProposalScriptRequirements)
-> PlutusRefScriptCliArgs -> CliProposalScriptRequirements
forall a b. (a -> b) -> a -> b
$ TxIn
-> AnyPlutusScriptVersion
-> ScriptDataOrFile
-> ExecutionUnits
-> PlutusRefScriptCliArgs
PlutusRefScriptCliArgs TxIn
txIn AnyPlutusScriptVersion
version ScriptDataOrFile
redeemer ExecutionUnits
execUnits