{-# LANGUAGE DeriveAnyClass #-}

module Hercules.API.Agents.AgentInfo where

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

data AgentInfo = AgentInfo
  { AgentInfo -> Text
hostname :: Text,
    AgentInfo -> Text
agentVersion :: Text,
    AgentInfo -> Text
nixVersion :: Text,
    AgentInfo -> [Text]
platforms :: [Text],
    AgentInfo -> [Text]
systemFeatures :: [Text],
    AgentInfo -> [Text]
cachixPushCaches :: [Text],
    AgentInfo -> [Text]
substituters :: [Text],
    AgentInfo -> Int
concurrentTasks :: Int
  }
  deriving (forall x. Rep AgentInfo x -> AgentInfo
forall x. AgentInfo -> Rep AgentInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AgentInfo x -> AgentInfo
$cfrom :: forall x. AgentInfo -> Rep AgentInfo x
Generic, Int -> AgentInfo -> ShowS
[AgentInfo] -> ShowS
AgentInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AgentInfo] -> ShowS
$cshowList :: [AgentInfo] -> ShowS
show :: AgentInfo -> String
$cshow :: AgentInfo -> String
showsPrec :: Int -> AgentInfo -> ShowS
$cshowsPrec :: Int -> AgentInfo -> ShowS
Show, AgentInfo -> AgentInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AgentInfo -> AgentInfo -> Bool
$c/= :: AgentInfo -> AgentInfo -> Bool
== :: AgentInfo -> AgentInfo -> Bool
$c== :: AgentInfo -> AgentInfo -> Bool
Eq, AgentInfo -> ()
forall a. (a -> ()) -> NFData a
rnf :: AgentInfo -> ()
$crnf :: AgentInfo -> ()
NFData, [AgentInfo] -> Encoding
[AgentInfo] -> Value
AgentInfo -> Encoding
AgentInfo -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [AgentInfo] -> Encoding
$ctoEncodingList :: [AgentInfo] -> Encoding
toJSONList :: [AgentInfo] -> Value
$ctoJSONList :: [AgentInfo] -> Value
toEncoding :: AgentInfo -> Encoding
$ctoEncoding :: AgentInfo -> Encoding
toJSON :: AgentInfo -> Value
$ctoJSON :: AgentInfo -> Value
ToJSON, Proxy AgentInfo -> Declare (Definitions Schema) NamedSchema
forall a.
(Proxy a -> Declare (Definitions Schema) NamedSchema) -> ToSchema a
declareNamedSchema :: Proxy AgentInfo -> Declare (Definitions Schema) NamedSchema
$cdeclareNamedSchema :: Proxy AgentInfo -> Declare (Definitions Schema) NamedSchema
ToSchema)

instance FromJSON AgentInfo where
  parseJSON :: Value -> Parser AgentInfo
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
"concurrentTasks" 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 (Scientific -> Value
A.Number Scientific
2))