{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Batch.Types.NodeRangeProperty
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Batch.Types.NodeRangeProperty where

import Amazonka.Batch.Types.ContainerProperties
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object representing the properties of the node range for a multi-node
-- parallel job.
--
-- /See:/ 'newNodeRangeProperty' smart constructor.
data NodeRangeProperty = NodeRangeProperty'
  { -- | The container details for the node range.
    NodeRangeProperty -> Maybe ContainerProperties
container :: Prelude.Maybe ContainerProperties,
    -- | The range of nodes, using node index values. A range of @0:3@ indicates
    -- nodes with index values of @0@ through @3@. If the starting range value
    -- is omitted (@:n@), then @0@ is used to start the range. If the ending
    -- range value is omitted (@n:@), then the highest possible node index is
    -- used to end the range. Your accumulative node ranges must account for
    -- all nodes (@0:n@). You can nest node ranges, for example @0:10@ and
    -- @4:5@, in which case the @4:5@ range properties override the @0:10@
    -- properties.
    NodeRangeProperty -> Text
targetNodes :: Prelude.Text
  }
  deriving (NodeRangeProperty -> NodeRangeProperty -> Bool
(NodeRangeProperty -> NodeRangeProperty -> Bool)
-> (NodeRangeProperty -> NodeRangeProperty -> Bool)
-> Eq NodeRangeProperty
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeRangeProperty -> NodeRangeProperty -> Bool
$c/= :: NodeRangeProperty -> NodeRangeProperty -> Bool
== :: NodeRangeProperty -> NodeRangeProperty -> Bool
$c== :: NodeRangeProperty -> NodeRangeProperty -> Bool
Prelude.Eq, ReadPrec [NodeRangeProperty]
ReadPrec NodeRangeProperty
Int -> ReadS NodeRangeProperty
ReadS [NodeRangeProperty]
(Int -> ReadS NodeRangeProperty)
-> ReadS [NodeRangeProperty]
-> ReadPrec NodeRangeProperty
-> ReadPrec [NodeRangeProperty]
-> Read NodeRangeProperty
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NodeRangeProperty]
$creadListPrec :: ReadPrec [NodeRangeProperty]
readPrec :: ReadPrec NodeRangeProperty
$creadPrec :: ReadPrec NodeRangeProperty
readList :: ReadS [NodeRangeProperty]
$creadList :: ReadS [NodeRangeProperty]
readsPrec :: Int -> ReadS NodeRangeProperty
$creadsPrec :: Int -> ReadS NodeRangeProperty
Prelude.Read, Int -> NodeRangeProperty -> ShowS
[NodeRangeProperty] -> ShowS
NodeRangeProperty -> String
(Int -> NodeRangeProperty -> ShowS)
-> (NodeRangeProperty -> String)
-> ([NodeRangeProperty] -> ShowS)
-> Show NodeRangeProperty
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeRangeProperty] -> ShowS
$cshowList :: [NodeRangeProperty] -> ShowS
show :: NodeRangeProperty -> String
$cshow :: NodeRangeProperty -> String
showsPrec :: Int -> NodeRangeProperty -> ShowS
$cshowsPrec :: Int -> NodeRangeProperty -> ShowS
Prelude.Show, (forall x. NodeRangeProperty -> Rep NodeRangeProperty x)
-> (forall x. Rep NodeRangeProperty x -> NodeRangeProperty)
-> Generic NodeRangeProperty
forall x. Rep NodeRangeProperty x -> NodeRangeProperty
forall x. NodeRangeProperty -> Rep NodeRangeProperty x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NodeRangeProperty x -> NodeRangeProperty
$cfrom :: forall x. NodeRangeProperty -> Rep NodeRangeProperty x
Prelude.Generic)

-- |
-- Create a value of 'NodeRangeProperty' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'container', 'nodeRangeProperty_container' - The container details for the node range.
--
-- 'targetNodes', 'nodeRangeProperty_targetNodes' - The range of nodes, using node index values. A range of @0:3@ indicates
-- nodes with index values of @0@ through @3@. If the starting range value
-- is omitted (@:n@), then @0@ is used to start the range. If the ending
-- range value is omitted (@n:@), then the highest possible node index is
-- used to end the range. Your accumulative node ranges must account for
-- all nodes (@0:n@). You can nest node ranges, for example @0:10@ and
-- @4:5@, in which case the @4:5@ range properties override the @0:10@
-- properties.
newNodeRangeProperty ::
  -- | 'targetNodes'
  Prelude.Text ->
  NodeRangeProperty
newNodeRangeProperty :: Text -> NodeRangeProperty
newNodeRangeProperty Text
pTargetNodes_ =
  NodeRangeProperty' :: Maybe ContainerProperties -> Text -> NodeRangeProperty
NodeRangeProperty'
    { $sel:container:NodeRangeProperty' :: Maybe ContainerProperties
container = Maybe ContainerProperties
forall a. Maybe a
Prelude.Nothing,
      $sel:targetNodes:NodeRangeProperty' :: Text
targetNodes = Text
pTargetNodes_
    }

-- | The container details for the node range.
nodeRangeProperty_container :: Lens.Lens' NodeRangeProperty (Prelude.Maybe ContainerProperties)
nodeRangeProperty_container :: (Maybe ContainerProperties -> f (Maybe ContainerProperties))
-> NodeRangeProperty -> f NodeRangeProperty
nodeRangeProperty_container = (NodeRangeProperty -> Maybe ContainerProperties)
-> (NodeRangeProperty
    -> Maybe ContainerProperties -> NodeRangeProperty)
-> Lens
     NodeRangeProperty
     NodeRangeProperty
     (Maybe ContainerProperties)
     (Maybe ContainerProperties)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeRangeProperty' {Maybe ContainerProperties
container :: Maybe ContainerProperties
$sel:container:NodeRangeProperty' :: NodeRangeProperty -> Maybe ContainerProperties
container} -> Maybe ContainerProperties
container) (\s :: NodeRangeProperty
s@NodeRangeProperty' {} Maybe ContainerProperties
a -> NodeRangeProperty
s {$sel:container:NodeRangeProperty' :: Maybe ContainerProperties
container = Maybe ContainerProperties
a} :: NodeRangeProperty)

-- | The range of nodes, using node index values. A range of @0:3@ indicates
-- nodes with index values of @0@ through @3@. If the starting range value
-- is omitted (@:n@), then @0@ is used to start the range. If the ending
-- range value is omitted (@n:@), then the highest possible node index is
-- used to end the range. Your accumulative node ranges must account for
-- all nodes (@0:n@). You can nest node ranges, for example @0:10@ and
-- @4:5@, in which case the @4:5@ range properties override the @0:10@
-- properties.
nodeRangeProperty_targetNodes :: Lens.Lens' NodeRangeProperty Prelude.Text
nodeRangeProperty_targetNodes :: (Text -> f Text) -> NodeRangeProperty -> f NodeRangeProperty
nodeRangeProperty_targetNodes = (NodeRangeProperty -> Text)
-> (NodeRangeProperty -> Text -> NodeRangeProperty)
-> Lens NodeRangeProperty NodeRangeProperty Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeRangeProperty' {Text
targetNodes :: Text
$sel:targetNodes:NodeRangeProperty' :: NodeRangeProperty -> Text
targetNodes} -> Text
targetNodes) (\s :: NodeRangeProperty
s@NodeRangeProperty' {} Text
a -> NodeRangeProperty
s {$sel:targetNodes:NodeRangeProperty' :: Text
targetNodes = Text
a} :: NodeRangeProperty)

instance Core.FromJSON NodeRangeProperty where
  parseJSON :: Value -> Parser NodeRangeProperty
parseJSON =
    String
-> (Object -> Parser NodeRangeProperty)
-> Value
-> Parser NodeRangeProperty
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"NodeRangeProperty"
      ( \Object
x ->
          Maybe ContainerProperties -> Text -> NodeRangeProperty
NodeRangeProperty'
            (Maybe ContainerProperties -> Text -> NodeRangeProperty)
-> Parser (Maybe ContainerProperties)
-> Parser (Text -> NodeRangeProperty)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ContainerProperties)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"container")
            Parser (Text -> NodeRangeProperty)
-> Parser Text -> Parser NodeRangeProperty
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"targetNodes")
      )

instance Prelude.Hashable NodeRangeProperty

instance Prelude.NFData NodeRangeProperty

instance Core.ToJSON NodeRangeProperty where
  toJSON :: NodeRangeProperty -> Value
toJSON NodeRangeProperty' {Maybe ContainerProperties
Text
targetNodes :: Text
container :: Maybe ContainerProperties
$sel:targetNodes:NodeRangeProperty' :: NodeRangeProperty -> Text
$sel:container:NodeRangeProperty' :: NodeRangeProperty -> Maybe ContainerProperties
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"container" Text -> ContainerProperties -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ContainerProperties -> Pair)
-> Maybe ContainerProperties -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ContainerProperties
container,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"targetNodes" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
targetNodes)
          ]
      )