{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE OverloadedStrings #-}
module Language.Github.Actions.RunIf
( RunIf (..),
gen,
)
where
import Data.Aeson (FromJSON, ToJSON (..), Value (..))
import qualified Data.Aeson as Aeson
import Data.Text (Text)
import GHC.Generics (Generic)
import Hedgehog (MonadGen)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
data RunIf
= RunIfBool Bool
| RunIfString Text
deriving stock (RunIf -> RunIf -> Bool
(RunIf -> RunIf -> Bool) -> (RunIf -> RunIf -> Bool) -> Eq RunIf
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RunIf -> RunIf -> Bool
== :: RunIf -> RunIf -> Bool
$c/= :: RunIf -> RunIf -> Bool
/= :: RunIf -> RunIf -> Bool
Eq, (forall x. RunIf -> Rep RunIf x)
-> (forall x. Rep RunIf x -> RunIf) -> Generic RunIf
forall x. Rep RunIf x -> RunIf
forall x. RunIf -> Rep RunIf x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RunIf -> Rep RunIf x
from :: forall x. RunIf -> Rep RunIf x
$cto :: forall x. Rep RunIf x -> RunIf
to :: forall x. Rep RunIf x -> RunIf
Generic, Eq RunIf
Eq RunIf =>
(RunIf -> RunIf -> Ordering)
-> (RunIf -> RunIf -> Bool)
-> (RunIf -> RunIf -> Bool)
-> (RunIf -> RunIf -> Bool)
-> (RunIf -> RunIf -> Bool)
-> (RunIf -> RunIf -> RunIf)
-> (RunIf -> RunIf -> RunIf)
-> Ord RunIf
RunIf -> RunIf -> Bool
RunIf -> RunIf -> Ordering
RunIf -> RunIf -> RunIf
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: RunIf -> RunIf -> Ordering
compare :: RunIf -> RunIf -> Ordering
$c< :: RunIf -> RunIf -> Bool
< :: RunIf -> RunIf -> Bool
$c<= :: RunIf -> RunIf -> Bool
<= :: RunIf -> RunIf -> Bool
$c> :: RunIf -> RunIf -> Bool
> :: RunIf -> RunIf -> Bool
$c>= :: RunIf -> RunIf -> Bool
>= :: RunIf -> RunIf -> Bool
$cmax :: RunIf -> RunIf -> RunIf
max :: RunIf -> RunIf -> RunIf
$cmin :: RunIf -> RunIf -> RunIf
min :: RunIf -> RunIf -> RunIf
Ord, Int -> RunIf -> ShowS
[RunIf] -> ShowS
RunIf -> String
(Int -> RunIf -> ShowS)
-> (RunIf -> String) -> ([RunIf] -> ShowS) -> Show RunIf
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RunIf -> ShowS
showsPrec :: Int -> RunIf -> ShowS
$cshow :: RunIf -> String
show :: RunIf -> String
$cshowList :: [RunIf] -> ShowS
showList :: [RunIf] -> ShowS
Show)
instance FromJSON RunIf where
parseJSON :: Value -> Parser RunIf
parseJSON (Bool Bool
b) = RunIf -> Parser RunIf
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RunIf -> Parser RunIf) -> RunIf -> Parser RunIf
forall a b. (a -> b) -> a -> b
$ Bool -> RunIf
RunIfBool Bool
b
parseJSON (String Text
s) = RunIf -> Parser RunIf
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RunIf -> Parser RunIf) -> RunIf -> Parser RunIf
forall a b. (a -> b) -> a -> b
$ Text -> RunIf
RunIfString Text
s
parseJSON Value
v = String -> Parser RunIf
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser RunIf) -> String -> Parser RunIf
forall a b. (a -> b) -> a -> b
$ String
"Expected Bool or String for RunIf, got: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Value -> String
forall a. Show a => a -> String
show Value
v
instance ToJSON RunIf where
toJSON :: RunIf -> Value
toJSON (RunIfBool Bool
b) = Bool -> Value
Bool Bool
b
toJSON (RunIfString Text
s) = Text -> Value
String Text
s
gen :: (MonadGen m) => m RunIf
gen :: forall (m :: * -> *). MonadGen m => m RunIf
gen =
[m RunIf] -> m RunIf
forall (m :: * -> *) a. MonadGen m => [m a] -> m a
Gen.choice
[ Bool -> RunIf
RunIfBool (Bool -> RunIf) -> m Bool -> m RunIf
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Bool
forall (m :: * -> *). MonadGen m => m Bool
Gen.bool,
Text -> RunIf
RunIfString (Text -> RunIf) -> m Text -> m RunIf
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Int -> m Char -> m Text
forall (m :: * -> *). MonadGen m => Range Int -> m Char -> m Text
Gen.text (Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
5 Int
50) m Char
forall (m :: * -> *). MonadGen m => m Char
Gen.alphaNum
]