module Cardano.CLI.EraBased.Options.Governance.Poll
  ( pGovernancePollCmds
  )
where

import           Cardano.Api

import qualified Cardano.CLI.EraBased.Commands.Governance.Poll as Cmd
import           Cardano.CLI.EraBased.Options.Common
import           Cardano.CLI.Parser
import           Cardano.Prelude (catMaybes, isInfixOf)

import           Control.Monad (when)
import           Data.Foldable
import           Options.Applicative hiding (help, str)
import qualified Options.Applicative as Opt

pGovernancePollCmds
  :: ()
  => ShelleyBasedEra era
  -> Maybe (Parser (Cmd.GovernancePollCmds era))
pGovernancePollCmds :: forall era.
ShelleyBasedEra era -> Maybe (Parser (GovernancePollCmds era))
pGovernancePollCmds ShelleyBasedEra era
era =
  case [Parser (GovernancePollCmds era)]
parsers of
    [] -> Maybe (Parser (GovernancePollCmds era))
forall a. Maybe a
Nothing
    [Parser (GovernancePollCmds era)]
_ -> Parser (GovernancePollCmds era)
-> Maybe (Parser (GovernancePollCmds era))
forall a. a -> Maybe a
Just (Parser (GovernancePollCmds era)
 -> Maybe (Parser (GovernancePollCmds era)))
-> Parser (GovernancePollCmds era)
-> Maybe (Parser (GovernancePollCmds era))
forall a b. (a -> b) -> a -> b
$ [Parser (GovernancePollCmds era)]
-> Parser (GovernancePollCmds era)
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum [Parser (GovernancePollCmds era)]
parsers
 where
  parsers :: [Parser (GovernancePollCmds era)]
parsers =
    [Maybe (Parser (GovernancePollCmds era))]
-> [Parser (GovernancePollCmds era)]
forall a. [Maybe a] -> [a]
catMaybes
      [ String
-> ParserInfo (GovernancePollCmds era)
-> Parser (GovernancePollCmds era)
forall a. String -> ParserInfo a -> Parser a
subParser String
"create-poll"
          (ParserInfo (GovernancePollCmds era)
 -> Parser (GovernancePollCmds era))
-> Maybe (ParserInfo (GovernancePollCmds era))
-> Maybe (Parser (GovernancePollCmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( Parser (GovernancePollCmds era)
-> InfoMod (GovernancePollCmds era)
-> ParserInfo (GovernancePollCmds era)
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info
                  (Parser (GovernancePollCmds era)
 -> InfoMod (GovernancePollCmds era)
 -> ParserInfo (GovernancePollCmds era))
-> Maybe (Parser (GovernancePollCmds era))
-> Maybe
     (InfoMod (GovernancePollCmds era)
      -> ParserInfo (GovernancePollCmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era -> Maybe (Parser (GovernancePollCmds era))
forall era.
ShelleyBasedEra era -> Maybe (Parser (GovernancePollCmds era))
pGovernanceCreatePoll ShelleyBasedEra era
era
                  Maybe
  (InfoMod (GovernancePollCmds era)
   -> ParserInfo (GovernancePollCmds era))
-> Maybe (InfoMod (GovernancePollCmds era))
-> Maybe (ParserInfo (GovernancePollCmds era))
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> InfoMod (GovernancePollCmds era)
-> Maybe (InfoMod (GovernancePollCmds era))
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (String -> InfoMod (GovernancePollCmds era)
forall a. String -> InfoMod a
Opt.progDesc String
"Create an SPO poll")
              )
      , String
-> ParserInfo (GovernancePollCmds era)
-> Parser (GovernancePollCmds era)
forall a. String -> ParserInfo a -> Parser a
subParser String
"answer-poll"
          (ParserInfo (GovernancePollCmds era)
 -> Parser (GovernancePollCmds era))
-> Maybe (ParserInfo (GovernancePollCmds era))
-> Maybe (Parser (GovernancePollCmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( Parser (GovernancePollCmds era)
-> InfoMod (GovernancePollCmds era)
-> ParserInfo (GovernancePollCmds era)
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info
                  (Parser (GovernancePollCmds era)
 -> InfoMod (GovernancePollCmds era)
 -> ParserInfo (GovernancePollCmds era))
-> Maybe (Parser (GovernancePollCmds era))
-> Maybe
     (InfoMod (GovernancePollCmds era)
      -> ParserInfo (GovernancePollCmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era -> Maybe (Parser (GovernancePollCmds era))
forall era.
ShelleyBasedEra era -> Maybe (Parser (GovernancePollCmds era))
pGovernanceAnswerPoll ShelleyBasedEra era
era
                  Maybe
  (InfoMod (GovernancePollCmds era)
   -> ParserInfo (GovernancePollCmds era))
-> Maybe (InfoMod (GovernancePollCmds era))
-> Maybe (ParserInfo (GovernancePollCmds era))
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> InfoMod (GovernancePollCmds era)
-> Maybe (InfoMod (GovernancePollCmds era))
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (String -> InfoMod (GovernancePollCmds era)
forall a. String -> InfoMod a
Opt.progDesc String
"Answer an SPO poll")
              )
      , String
-> ParserInfo (GovernancePollCmds era)
-> Parser (GovernancePollCmds era)
forall a. String -> ParserInfo a -> Parser a
subParser String
"verify-poll"
          (ParserInfo (GovernancePollCmds era)
 -> Parser (GovernancePollCmds era))
-> Maybe (ParserInfo (GovernancePollCmds era))
-> Maybe (Parser (GovernancePollCmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( Parser (GovernancePollCmds era)
-> InfoMod (GovernancePollCmds era)
-> ParserInfo (GovernancePollCmds era)
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info
                  (Parser (GovernancePollCmds era)
 -> InfoMod (GovernancePollCmds era)
 -> ParserInfo (GovernancePollCmds era))
-> Maybe (Parser (GovernancePollCmds era))
-> Maybe
     (InfoMod (GovernancePollCmds era)
      -> ParserInfo (GovernancePollCmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era -> Maybe (Parser (GovernancePollCmds era))
forall era.
ShelleyBasedEra era -> Maybe (Parser (GovernancePollCmds era))
pGovernanceVerifyPoll ShelleyBasedEra era
era
                  Maybe
  (InfoMod (GovernancePollCmds era)
   -> ParserInfo (GovernancePollCmds era))
-> Maybe (InfoMod (GovernancePollCmds era))
-> Maybe (ParserInfo (GovernancePollCmds era))
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> InfoMod (GovernancePollCmds era)
-> Maybe (InfoMod (GovernancePollCmds era))
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (String -> InfoMod (GovernancePollCmds era)
forall a. String -> InfoMod a
Opt.progDesc String
"Verify an answer to a given SPO poll")
              )
      ]

pGovernanceCreatePoll :: ShelleyBasedEra era -> Maybe (Parser (Cmd.GovernancePollCmds era))
pGovernanceCreatePoll :: forall era.
ShelleyBasedEra era -> Maybe (Parser (GovernancePollCmds era))
pGovernanceCreatePoll ShelleyBasedEra era
era = do
  BabbageEraOnwards era
w <- ShelleyBasedEra era -> Maybe (BabbageEraOnwards era)
forall (eon :: * -> *) era.
Eon eon =>
ShelleyBasedEra era -> Maybe (eon era)
forShelleyBasedEraMaybeEon ShelleyBasedEra era
era
  Bool -> Maybe () -> Maybe ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (String
"BabbageEraOnwardsConway" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isInfixOf` BabbageEraOnwards era -> String
forall a. Show a => a -> String
show BabbageEraOnwards era
w) Maybe ()
forall a. Maybe a
Nothing
  Parser (GovernancePollCmds era)
-> Maybe (Parser (GovernancePollCmds era))
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Parser (GovernancePollCmds era)
 -> Maybe (Parser (GovernancePollCmds era)))
-> Parser (GovernancePollCmds era)
-> Maybe (Parser (GovernancePollCmds era))
forall a b. (a -> b) -> a -> b
$
    (GovernanceCreatePollCmdArgs era -> GovernancePollCmds era)
-> Parser (GovernanceCreatePollCmdArgs era)
-> Parser (GovernancePollCmds era)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GovernanceCreatePollCmdArgs era -> GovernancePollCmds era
forall era.
GovernanceCreatePollCmdArgs era -> GovernancePollCmds era
Cmd.GovernanceCreatePoll (Parser (GovernanceCreatePollCmdArgs era)
 -> Parser (GovernancePollCmds era))
-> Parser (GovernanceCreatePollCmdArgs era)
-> Parser (GovernancePollCmds era)
forall a b. (a -> b) -> a -> b
$
      BabbageEraOnwards era
-> Text
-> [Text]
-> Maybe Word
-> File GovernancePoll 'Out
-> GovernanceCreatePollCmdArgs era
forall era.
BabbageEraOnwards era
-> Text
-> [Text]
-> Maybe Word
-> File GovernancePoll 'Out
-> GovernanceCreatePollCmdArgs era
Cmd.GovernanceCreatePollCmdArgs BabbageEraOnwards era
w
        (Text
 -> [Text]
 -> Maybe Word
 -> File GovernancePoll 'Out
 -> GovernanceCreatePollCmdArgs era)
-> Parser Text
-> Parser
     ([Text]
      -> Maybe Word
      -> File GovernancePoll 'Out
      -> GovernanceCreatePollCmdArgs era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
pPollQuestion
        Parser
  ([Text]
   -> Maybe Word
   -> File GovernancePoll 'Out
   -> GovernanceCreatePollCmdArgs era)
-> Parser [Text]
-> Parser
     (Maybe Word
      -> File GovernancePoll 'Out -> GovernanceCreatePollCmdArgs era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Text -> Parser [Text]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Parser Text
pPollAnswer
        Parser
  (Maybe Word
   -> File GovernancePoll 'Out -> GovernanceCreatePollCmdArgs era)
-> Parser (Maybe Word)
-> Parser
     (File GovernancePoll 'Out -> GovernanceCreatePollCmdArgs era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Word -> Parser (Maybe Word)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser Word
pPollNonce
        Parser
  (File GovernancePoll 'Out -> GovernanceCreatePollCmdArgs era)
-> Parser (File GovernancePoll 'Out)
-> Parser (GovernanceCreatePollCmdArgs era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (File GovernancePoll 'Out)
forall content. Parser (File content 'Out)
pOutputFile

pGovernanceAnswerPoll :: ShelleyBasedEra era -> Maybe (Parser (Cmd.GovernancePollCmds era))
pGovernanceAnswerPoll :: forall era.
ShelleyBasedEra era -> Maybe (Parser (GovernancePollCmds era))
pGovernanceAnswerPoll ShelleyBasedEra era
era = do
  BabbageEraOnwards era
w <- ShelleyBasedEra era -> Maybe (BabbageEraOnwards era)
forall (eon :: * -> *) era.
Eon eon =>
ShelleyBasedEra era -> Maybe (eon era)
forShelleyBasedEraMaybeEon ShelleyBasedEra era
era
  Bool -> Maybe () -> Maybe ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (String
"BabbageEraOnwardsConway" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isInfixOf` BabbageEraOnwards era -> String
forall a. Show a => a -> String
show BabbageEraOnwards era
w) Maybe ()
forall a. Maybe a
Nothing
  Parser (GovernancePollCmds era)
-> Maybe (Parser (GovernancePollCmds era))
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Parser (GovernancePollCmds era)
 -> Maybe (Parser (GovernancePollCmds era)))
-> Parser (GovernancePollCmds era)
-> Maybe (Parser (GovernancePollCmds era))
forall a b. (a -> b) -> a -> b
$
    (GovernanceAnswerPollCmdArgs era -> GovernancePollCmds era)
-> Parser (GovernanceAnswerPollCmdArgs era)
-> Parser (GovernancePollCmds era)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GovernanceAnswerPollCmdArgs era -> GovernancePollCmds era
forall era.
GovernanceAnswerPollCmdArgs era -> GovernancePollCmds era
Cmd.GovernanceAnswerPoll (Parser (GovernanceAnswerPollCmdArgs era)
 -> Parser (GovernancePollCmds era))
-> Parser (GovernanceAnswerPollCmdArgs era)
-> Parser (GovernancePollCmds era)
forall a b. (a -> b) -> a -> b
$
      BabbageEraOnwards era
-> File GovernancePoll 'In
-> Maybe Word
-> Maybe (File () 'Out)
-> GovernanceAnswerPollCmdArgs era
forall era.
BabbageEraOnwards era
-> File GovernancePoll 'In
-> Maybe Word
-> Maybe (File () 'Out)
-> GovernanceAnswerPollCmdArgs era
Cmd.GovernanceAnswerPollCmdArgs BabbageEraOnwards era
w
        (File GovernancePoll 'In
 -> Maybe Word
 -> Maybe (File () 'Out)
 -> GovernanceAnswerPollCmdArgs era)
-> Parser (File GovernancePoll 'In)
-> Parser
     (Maybe Word
      -> Maybe (File () 'Out) -> GovernanceAnswerPollCmdArgs era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (File GovernancePoll 'In)
pPollFile
        Parser
  (Maybe Word
   -> Maybe (File () 'Out) -> GovernanceAnswerPollCmdArgs era)
-> Parser (Maybe Word)
-> Parser (Maybe (File () 'Out) -> GovernanceAnswerPollCmdArgs era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Word -> Parser (Maybe Word)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser Word
pPollAnswerIndex
        Parser (Maybe (File () 'Out) -> GovernanceAnswerPollCmdArgs era)
-> Parser (Maybe (File () 'Out))
-> Parser (GovernanceAnswerPollCmdArgs era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (File () 'Out) -> Parser (Maybe (File () 'Out))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser (File () 'Out)
forall content. Parser (File content 'Out)
pOutputFile

pGovernanceVerifyPoll :: ShelleyBasedEra era -> Maybe (Parser (Cmd.GovernancePollCmds era))
pGovernanceVerifyPoll :: forall era.
ShelleyBasedEra era -> Maybe (Parser (GovernancePollCmds era))
pGovernanceVerifyPoll ShelleyBasedEra era
era = do
  BabbageEraOnwards era
w <- ShelleyBasedEra era -> Maybe (BabbageEraOnwards era)
forall (eon :: * -> *) era.
Eon eon =>
ShelleyBasedEra era -> Maybe (eon era)
forShelleyBasedEraMaybeEon ShelleyBasedEra era
era
  Bool -> Maybe () -> Maybe ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (String
"BabbageEraOnwardsConway" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isInfixOf` BabbageEraOnwards era -> String
forall a. Show a => a -> String
show BabbageEraOnwards era
w) Maybe ()
forall a. Maybe a
Nothing
  Parser (GovernancePollCmds era)
-> Maybe (Parser (GovernancePollCmds era))
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Parser (GovernancePollCmds era)
 -> Maybe (Parser (GovernancePollCmds era)))
-> Parser (GovernancePollCmds era)
-> Maybe (Parser (GovernancePollCmds era))
forall a b. (a -> b) -> a -> b
$
    (GovernanceVerifyPollCmdArgs era -> GovernancePollCmds era)
-> Parser (GovernanceVerifyPollCmdArgs era)
-> Parser (GovernancePollCmds era)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GovernanceVerifyPollCmdArgs era -> GovernancePollCmds era
forall era.
GovernanceVerifyPollCmdArgs era -> GovernancePollCmds era
Cmd.GovernanceVerifyPoll (Parser (GovernanceVerifyPollCmdArgs era)
 -> Parser (GovernancePollCmds era))
-> Parser (GovernanceVerifyPollCmdArgs era)
-> Parser (GovernancePollCmds era)
forall a b. (a -> b) -> a -> b
$
      BabbageEraOnwards era
-> File GovernancePoll 'In
-> File (Tx ()) 'In
-> Maybe (File () 'Out)
-> GovernanceVerifyPollCmdArgs era
forall era.
BabbageEraOnwards era
-> File GovernancePoll 'In
-> File (Tx ()) 'In
-> Maybe (File () 'Out)
-> GovernanceVerifyPollCmdArgs era
Cmd.GovernanceVerifyPollCmdArgs BabbageEraOnwards era
w
        (File GovernancePoll 'In
 -> File (Tx ()) 'In
 -> Maybe (File () 'Out)
 -> GovernanceVerifyPollCmdArgs era)
-> Parser (File GovernancePoll 'In)
-> Parser
     (File (Tx ()) 'In
      -> Maybe (File () 'Out) -> GovernanceVerifyPollCmdArgs era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (File GovernancePoll 'In)
pPollFile
        Parser
  (File (Tx ()) 'In
   -> Maybe (File () 'Out) -> GovernanceVerifyPollCmdArgs era)
-> Parser (File (Tx ()) 'In)
-> Parser (Maybe (File () 'Out) -> GovernanceVerifyPollCmdArgs era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (File (Tx ()) 'In)
pPollTxFile
        Parser (Maybe (File () 'Out) -> GovernanceVerifyPollCmdArgs era)
-> Parser (Maybe (File () 'Out))
-> Parser (GovernanceVerifyPollCmdArgs era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (File () 'Out) -> Parser (Maybe (File () 'Out))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser (File () 'Out)
forall content. Parser (File content 'Out)
pOutputFile