{-# LANGUAGE DeriveAnyClass #-}

module Hercules.API.Agent.Evaluate.EvaluateEvent.OnPushHandlerEvent where

import Control.Applicative ((<|>))
import Control.Lens (at, (%~))
import qualified Data.Aeson as A
import Data.Aeson.Lens (_Object)
import Hercules.API.Agent.Evaluate.EvaluateEvent.InputDeclaration (InputDeclaration)
import Hercules.API.Prelude

data OnPushHandlerEvent = OnPushHandlerEvent
  { OnPushHandlerEvent -> Text
handlerName :: Text,
    OnPushHandlerEvent -> Map Text InputDeclaration
handlerExtraInputs :: Map Text InputDeclaration,
    OnPushHandlerEvent -> Bool
isFlake :: Bool
  }
  deriving (forall x. Rep OnPushHandlerEvent x -> OnPushHandlerEvent
forall x. OnPushHandlerEvent -> Rep OnPushHandlerEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OnPushHandlerEvent x -> OnPushHandlerEvent
$cfrom :: forall x. OnPushHandlerEvent -> Rep OnPushHandlerEvent x
Generic, Int -> OnPushHandlerEvent -> ShowS
[OnPushHandlerEvent] -> ShowS
OnPushHandlerEvent -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OnPushHandlerEvent] -> ShowS
$cshowList :: [OnPushHandlerEvent] -> ShowS
show :: OnPushHandlerEvent -> String
$cshow :: OnPushHandlerEvent -> String
showsPrec :: Int -> OnPushHandlerEvent -> ShowS
$cshowsPrec :: Int -> OnPushHandlerEvent -> ShowS
Show, OnPushHandlerEvent -> OnPushHandlerEvent -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OnPushHandlerEvent -> OnPushHandlerEvent -> Bool
$c/= :: OnPushHandlerEvent -> OnPushHandlerEvent -> Bool
== :: OnPushHandlerEvent -> OnPushHandlerEvent -> Bool
$c== :: OnPushHandlerEvent -> OnPushHandlerEvent -> Bool
Eq, OnPushHandlerEvent -> ()
forall a. (a -> ()) -> NFData a
rnf :: OnPushHandlerEvent -> ()
$crnf :: OnPushHandlerEvent -> ()
NFData, [OnPushHandlerEvent] -> Encoding
[OnPushHandlerEvent] -> Value
OnPushHandlerEvent -> Encoding
OnPushHandlerEvent -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [OnPushHandlerEvent] -> Encoding
$ctoEncodingList :: [OnPushHandlerEvent] -> Encoding
toJSONList :: [OnPushHandlerEvent] -> Value
$ctoJSONList :: [OnPushHandlerEvent] -> Value
toEncoding :: OnPushHandlerEvent -> Encoding
$ctoEncoding :: OnPushHandlerEvent -> Encoding
toJSON :: OnPushHandlerEvent -> Value
$ctoJSON :: OnPushHandlerEvent -> Value
ToJSON)

instance FromJSON OnPushHandlerEvent where
  parseJSON :: Value -> Parser OnPushHandlerEvent
parseJSON = forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
A.genericParseJSON Options
A.defaultOptions forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Value
fixup
    where
      fixup :: A.Value -> A.Value
      fixup :: Value -> Value
fixup = forall t. AsValue t => Prism' t (KeyMap Value)
_Object forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Key
"isFlake" forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. a -> Maybe a
Just (Bool -> Value
A.Bool Bool
False))