{-# LANGUAGE ApplicativeDo         #-}
{-# LANGUAGE DataKinds             #-}
{-# LANGUAGE DeriveAnyClass        #-}
{-# LANGUAGE DeriveGeneric         #-}
{-# LANGUAGE DerivingVia           #-}
{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables   #-}

module Plutus.PAB.Run.Command
    ( ConfigCommand(..)
    , allServices
    ) where

import Data.Aeson qualified as JSON
import GHC.Generics (Generic)
import Wallet.Types (ContractInstanceId)

-- | A command for which a config.yaml file is required
data ConfigCommand =
    Migrate
    | StartNode -- ^ Run the mock node service
    | MockWallet -- ^ Run the mock wallet service
    | ChainIndex -- ^ Run the chain index service
    | ForkCommands [ConfigCommand] -- ^ Fork a list of commands
    | ContractState ContractInstanceId -- ^ Display the contract identified by 'ContractInstanceId'
    | ReportContractHistory ContractInstanceId -- ^ Get the history of the contract identified by 'UUID'
    | ReportAvailableContracts -- ^ Get all available contracts
    | ReportActiveContracts -- ^ Get active contracts
    | PABWebserver -- ^ Run the PAB webserver
    deriving stock (Int -> ConfigCommand -> ShowS
[ConfigCommand] -> ShowS
ConfigCommand -> String
(Int -> ConfigCommand -> ShowS)
-> (ConfigCommand -> String)
-> ([ConfigCommand] -> ShowS)
-> Show ConfigCommand
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfigCommand] -> ShowS
$cshowList :: [ConfigCommand] -> ShowS
show :: ConfigCommand -> String
$cshow :: ConfigCommand -> String
showsPrec :: Int -> ConfigCommand -> ShowS
$cshowsPrec :: Int -> ConfigCommand -> ShowS
Show, ConfigCommand -> ConfigCommand -> Bool
(ConfigCommand -> ConfigCommand -> Bool)
-> (ConfigCommand -> ConfigCommand -> Bool) -> Eq ConfigCommand
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfigCommand -> ConfigCommand -> Bool
$c/= :: ConfigCommand -> ConfigCommand -> Bool
== :: ConfigCommand -> ConfigCommand -> Bool
$c== :: ConfigCommand -> ConfigCommand -> Bool
Eq, (forall x. ConfigCommand -> Rep ConfigCommand x)
-> (forall x. Rep ConfigCommand x -> ConfigCommand)
-> Generic ConfigCommand
forall x. Rep ConfigCommand x -> ConfigCommand
forall x. ConfigCommand -> Rep ConfigCommand x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConfigCommand x -> ConfigCommand
$cfrom :: forall x. ConfigCommand -> Rep ConfigCommand x
Generic)
    deriving anyclass [ConfigCommand] -> Encoding
[ConfigCommand] -> Value
ConfigCommand -> Encoding
ConfigCommand -> Value
(ConfigCommand -> Value)
-> (ConfigCommand -> Encoding)
-> ([ConfigCommand] -> Value)
-> ([ConfigCommand] -> Encoding)
-> ToJSON ConfigCommand
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [ConfigCommand] -> Encoding
$ctoEncodingList :: [ConfigCommand] -> Encoding
toJSONList :: [ConfigCommand] -> Value
$ctoJSONList :: [ConfigCommand] -> Value
toEncoding :: ConfigCommand -> Encoding
$ctoEncoding :: ConfigCommand -> Encoding
toJSON :: ConfigCommand -> Value
$ctoJSON :: ConfigCommand -> Value
JSON.ToJSON


-- | A single command to the PAB that spins up all the necessary services.
allServices :: ConfigCommand
allServices :: ConfigCommand
allServices =
  [ConfigCommand] -> ConfigCommand
ForkCommands
    [ ConfigCommand
StartNode
    , ConfigCommand
MockWallet
    , ConfigCommand
PABWebserver
    , ConfigCommand
ChainIndex
    ]