{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveAnyClass #-}

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

import Control.Applicative
import Control.Lens (at, (%~))
import qualified Data.Aeson as A
import Data.Aeson.Lens (_Object)
import Hercules.API.Prelude

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

instance FromJSON BuildRequest where
  parseJSON :: Value -> Parser BuildRequest
parseJSON = Options -> Value -> Parser BuildRequest
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
A.genericParseJSON Options
A.defaultOptions (Value -> Parser BuildRequest)
-> (Value -> Value) -> Value -> Parser BuildRequest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Value
fixup
    where
      fixup :: A.Value -> A.Value
      fixup :: Value -> Value
fixup = (HashMap Text Value -> Identity (HashMap Text Value))
-> Value -> Identity Value
forall t. AsValue t => Prism' t (HashMap Text Value)
_Object ((HashMap Text Value -> Identity (HashMap Text Value))
 -> Value -> Identity Value)
-> ((Maybe Value -> Identity (Maybe Value))
    -> HashMap Text Value -> Identity (HashMap Text Value))
-> (Maybe Value -> Identity (Maybe Value))
-> Value
-> Identity Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (HashMap Text Value)
-> Lens'
     (HashMap Text Value) (Maybe (IxValue (HashMap Text Value)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Index (HashMap Text Value)
"forceRebuild" ((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 (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))