{-# 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.ComputeEnvironmentOrder
-- 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.ComputeEnvironmentOrder where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The order in which compute environments are tried for job placement
-- within a queue. Compute environments are tried in ascending order. For
-- example, if two compute environments are associated with a job queue,
-- the compute environment with a lower order integer value is tried for
-- job placement first. Compute environments must be in the @VALID@ state
-- before you can associate them with a job queue. All of the compute
-- environments must be either EC2 (@EC2@ or @SPOT@) or Fargate (@FARGATE@
-- or @FARGATE_SPOT@); EC2 and Fargate compute environments can\'t be
-- mixed.
--
-- All compute environments that are associated with a job queue must share
-- the same architecture. Batch doesn\'t support mixing compute environment
-- architecture types in a single job queue.
--
-- /See:/ 'newComputeEnvironmentOrder' smart constructor.
data ComputeEnvironmentOrder = ComputeEnvironmentOrder'
  { -- | The order of the compute environment. Compute environments are tried in
    -- ascending order. For example, if two compute environments are associated
    -- with a job queue, the compute environment with a lower @order@ integer
    -- value is tried for job placement first.
    ComputeEnvironmentOrder -> Int
order :: Prelude.Int,
    -- | The Amazon Resource Name (ARN) of the compute environment.
    ComputeEnvironmentOrder -> Text
computeEnvironment :: Prelude.Text
  }
  deriving (ComputeEnvironmentOrder -> ComputeEnvironmentOrder -> Bool
(ComputeEnvironmentOrder -> ComputeEnvironmentOrder -> Bool)
-> (ComputeEnvironmentOrder -> ComputeEnvironmentOrder -> Bool)
-> Eq ComputeEnvironmentOrder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ComputeEnvironmentOrder -> ComputeEnvironmentOrder -> Bool
$c/= :: ComputeEnvironmentOrder -> ComputeEnvironmentOrder -> Bool
== :: ComputeEnvironmentOrder -> ComputeEnvironmentOrder -> Bool
$c== :: ComputeEnvironmentOrder -> ComputeEnvironmentOrder -> Bool
Prelude.Eq, ReadPrec [ComputeEnvironmentOrder]
ReadPrec ComputeEnvironmentOrder
Int -> ReadS ComputeEnvironmentOrder
ReadS [ComputeEnvironmentOrder]
(Int -> ReadS ComputeEnvironmentOrder)
-> ReadS [ComputeEnvironmentOrder]
-> ReadPrec ComputeEnvironmentOrder
-> ReadPrec [ComputeEnvironmentOrder]
-> Read ComputeEnvironmentOrder
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ComputeEnvironmentOrder]
$creadListPrec :: ReadPrec [ComputeEnvironmentOrder]
readPrec :: ReadPrec ComputeEnvironmentOrder
$creadPrec :: ReadPrec ComputeEnvironmentOrder
readList :: ReadS [ComputeEnvironmentOrder]
$creadList :: ReadS [ComputeEnvironmentOrder]
readsPrec :: Int -> ReadS ComputeEnvironmentOrder
$creadsPrec :: Int -> ReadS ComputeEnvironmentOrder
Prelude.Read, Int -> ComputeEnvironmentOrder -> ShowS
[ComputeEnvironmentOrder] -> ShowS
ComputeEnvironmentOrder -> String
(Int -> ComputeEnvironmentOrder -> ShowS)
-> (ComputeEnvironmentOrder -> String)
-> ([ComputeEnvironmentOrder] -> ShowS)
-> Show ComputeEnvironmentOrder
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ComputeEnvironmentOrder] -> ShowS
$cshowList :: [ComputeEnvironmentOrder] -> ShowS
show :: ComputeEnvironmentOrder -> String
$cshow :: ComputeEnvironmentOrder -> String
showsPrec :: Int -> ComputeEnvironmentOrder -> ShowS
$cshowsPrec :: Int -> ComputeEnvironmentOrder -> ShowS
Prelude.Show, (forall x.
 ComputeEnvironmentOrder -> Rep ComputeEnvironmentOrder x)
-> (forall x.
    Rep ComputeEnvironmentOrder x -> ComputeEnvironmentOrder)
-> Generic ComputeEnvironmentOrder
forall x. Rep ComputeEnvironmentOrder x -> ComputeEnvironmentOrder
forall x. ComputeEnvironmentOrder -> Rep ComputeEnvironmentOrder x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ComputeEnvironmentOrder x -> ComputeEnvironmentOrder
$cfrom :: forall x. ComputeEnvironmentOrder -> Rep ComputeEnvironmentOrder x
Prelude.Generic)

-- |
-- Create a value of 'ComputeEnvironmentOrder' 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:
--
-- 'order', 'computeEnvironmentOrder_order' - The order of the compute environment. Compute environments are tried in
-- ascending order. For example, if two compute environments are associated
-- with a job queue, the compute environment with a lower @order@ integer
-- value is tried for job placement first.
--
-- 'computeEnvironment', 'computeEnvironmentOrder_computeEnvironment' - The Amazon Resource Name (ARN) of the compute environment.
newComputeEnvironmentOrder ::
  -- | 'order'
  Prelude.Int ->
  -- | 'computeEnvironment'
  Prelude.Text ->
  ComputeEnvironmentOrder
newComputeEnvironmentOrder :: Int -> Text -> ComputeEnvironmentOrder
newComputeEnvironmentOrder
  Int
pOrder_
  Text
pComputeEnvironment_ =
    ComputeEnvironmentOrder' :: Int -> Text -> ComputeEnvironmentOrder
ComputeEnvironmentOrder'
      { $sel:order:ComputeEnvironmentOrder' :: Int
order = Int
pOrder_,
        $sel:computeEnvironment:ComputeEnvironmentOrder' :: Text
computeEnvironment = Text
pComputeEnvironment_
      }

-- | The order of the compute environment. Compute environments are tried in
-- ascending order. For example, if two compute environments are associated
-- with a job queue, the compute environment with a lower @order@ integer
-- value is tried for job placement first.
computeEnvironmentOrder_order :: Lens.Lens' ComputeEnvironmentOrder Prelude.Int
computeEnvironmentOrder_order :: (Int -> f Int)
-> ComputeEnvironmentOrder -> f ComputeEnvironmentOrder
computeEnvironmentOrder_order = (ComputeEnvironmentOrder -> Int)
-> (ComputeEnvironmentOrder -> Int -> ComputeEnvironmentOrder)
-> Lens ComputeEnvironmentOrder ComputeEnvironmentOrder Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComputeEnvironmentOrder' {Int
order :: Int
$sel:order:ComputeEnvironmentOrder' :: ComputeEnvironmentOrder -> Int
order} -> Int
order) (\s :: ComputeEnvironmentOrder
s@ComputeEnvironmentOrder' {} Int
a -> ComputeEnvironmentOrder
s {$sel:order:ComputeEnvironmentOrder' :: Int
order = Int
a} :: ComputeEnvironmentOrder)

-- | The Amazon Resource Name (ARN) of the compute environment.
computeEnvironmentOrder_computeEnvironment :: Lens.Lens' ComputeEnvironmentOrder Prelude.Text
computeEnvironmentOrder_computeEnvironment :: (Text -> f Text)
-> ComputeEnvironmentOrder -> f ComputeEnvironmentOrder
computeEnvironmentOrder_computeEnvironment = (ComputeEnvironmentOrder -> Text)
-> (ComputeEnvironmentOrder -> Text -> ComputeEnvironmentOrder)
-> Lens ComputeEnvironmentOrder ComputeEnvironmentOrder Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComputeEnvironmentOrder' {Text
computeEnvironment :: Text
$sel:computeEnvironment:ComputeEnvironmentOrder' :: ComputeEnvironmentOrder -> Text
computeEnvironment} -> Text
computeEnvironment) (\s :: ComputeEnvironmentOrder
s@ComputeEnvironmentOrder' {} Text
a -> ComputeEnvironmentOrder
s {$sel:computeEnvironment:ComputeEnvironmentOrder' :: Text
computeEnvironment = Text
a} :: ComputeEnvironmentOrder)

instance Core.FromJSON ComputeEnvironmentOrder where
  parseJSON :: Value -> Parser ComputeEnvironmentOrder
parseJSON =
    String
-> (Object -> Parser ComputeEnvironmentOrder)
-> Value
-> Parser ComputeEnvironmentOrder
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ComputeEnvironmentOrder"
      ( \Object
x ->
          Int -> Text -> ComputeEnvironmentOrder
ComputeEnvironmentOrder'
            (Int -> Text -> ComputeEnvironmentOrder)
-> Parser Int -> Parser (Text -> ComputeEnvironmentOrder)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"order")
            Parser (Text -> ComputeEnvironmentOrder)
-> Parser Text -> Parser ComputeEnvironmentOrder
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
"computeEnvironment")
      )

instance Prelude.Hashable ComputeEnvironmentOrder

instance Prelude.NFData ComputeEnvironmentOrder

instance Core.ToJSON ComputeEnvironmentOrder where
  toJSON :: ComputeEnvironmentOrder -> Value
toJSON ComputeEnvironmentOrder' {Int
Text
computeEnvironment :: Text
order :: Int
$sel:computeEnvironment:ComputeEnvironmentOrder' :: ComputeEnvironmentOrder -> Text
$sel:order:ComputeEnvironmentOrder' :: ComputeEnvironmentOrder -> Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"order" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
order),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"computeEnvironment" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
computeEnvironment)
          ]
      )