{-# 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. OnPushHandlerEvent -> Rep OnPushHandlerEvent x)
-> (forall x. Rep OnPushHandlerEvent x -> OnPushHandlerEvent)
-> Generic OnPushHandlerEvent
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
$cfrom :: forall x. OnPushHandlerEvent -> Rep OnPushHandlerEvent x
from :: forall x. OnPushHandlerEvent -> Rep OnPushHandlerEvent x
$cto :: forall x. Rep OnPushHandlerEvent x -> OnPushHandlerEvent
to :: forall x. Rep OnPushHandlerEvent x -> OnPushHandlerEvent
Generic, Int -> OnPushHandlerEvent -> ShowS
[OnPushHandlerEvent] -> ShowS
OnPushHandlerEvent -> String
(Int -> OnPushHandlerEvent -> ShowS)
-> (OnPushHandlerEvent -> String)
-> ([OnPushHandlerEvent] -> ShowS)
-> Show OnPushHandlerEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OnPushHandlerEvent -> ShowS
showsPrec :: Int -> OnPushHandlerEvent -> ShowS
$cshow :: OnPushHandlerEvent -> String
show :: OnPushHandlerEvent -> String
$cshowList :: [OnPushHandlerEvent] -> ShowS
showList :: [OnPushHandlerEvent] -> ShowS
Show, OnPushHandlerEvent -> OnPushHandlerEvent -> Bool
(OnPushHandlerEvent -> OnPushHandlerEvent -> Bool)
-> (OnPushHandlerEvent -> OnPushHandlerEvent -> Bool)
-> Eq OnPushHandlerEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OnPushHandlerEvent -> OnPushHandlerEvent -> Bool
== :: OnPushHandlerEvent -> OnPushHandlerEvent -> Bool
$c/= :: OnPushHandlerEvent -> OnPushHandlerEvent -> Bool
/= :: OnPushHandlerEvent -> OnPushHandlerEvent -> Bool
Eq, OnPushHandlerEvent -> ()
(OnPushHandlerEvent -> ()) -> NFData OnPushHandlerEvent
forall a. (a -> ()) -> NFData a
$crnf :: OnPushHandlerEvent -> ()
rnf :: OnPushHandlerEvent -> ()
NFData, [OnPushHandlerEvent] -> Value
[OnPushHandlerEvent] -> Encoding
OnPushHandlerEvent -> Value
OnPushHandlerEvent -> Encoding
(OnPushHandlerEvent -> Value)
-> (OnPushHandlerEvent -> Encoding)
-> ([OnPushHandlerEvent] -> Value)
-> ([OnPushHandlerEvent] -> Encoding)
-> ToJSON OnPushHandlerEvent
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: OnPushHandlerEvent -> Value
toJSON :: OnPushHandlerEvent -> Value
$ctoEncoding :: OnPushHandlerEvent -> Encoding
toEncoding :: OnPushHandlerEvent -> Encoding
$ctoJSONList :: [OnPushHandlerEvent] -> Value
toJSONList :: [OnPushHandlerEvent] -> Value
$ctoEncodingList :: [OnPushHandlerEvent] -> Encoding
toEncodingList :: [OnPushHandlerEvent] -> Encoding
ToJSON)

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