{-# 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.ECS.Types.PlacementConstraint
-- 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.ECS.Types.PlacementConstraint where

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types.PlacementConstraintType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object representing a constraint on task placement. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement-constraints.html Task Placement Constraints>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- If you are using the Fargate launch type, task placement constraints are
-- not supported.
--
-- /See:/ 'newPlacementConstraint' smart constructor.
data PlacementConstraint = PlacementConstraint'
  { -- | A cluster query language expression to apply to the constraint. The
    -- expression can have a maximum length of 2000 characters. You can\'t
    -- specify an expression if the constraint type is @distinctInstance@. For
    -- more information, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html Cluster query language>
    -- in the /Amazon Elastic Container Service Developer Guide/.
    PlacementConstraint -> Maybe Text
expression :: Prelude.Maybe Prelude.Text,
    -- | The type of constraint. Use @distinctInstance@ to ensure that each task
    -- in a particular group is running on a different container instance. Use
    -- @memberOf@ to restrict the selection to a group of valid candidates.
    PlacementConstraint -> Maybe PlacementConstraintType
type' :: Prelude.Maybe PlacementConstraintType
  }
  deriving (PlacementConstraint -> PlacementConstraint -> Bool
(PlacementConstraint -> PlacementConstraint -> Bool)
-> (PlacementConstraint -> PlacementConstraint -> Bool)
-> Eq PlacementConstraint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PlacementConstraint -> PlacementConstraint -> Bool
$c/= :: PlacementConstraint -> PlacementConstraint -> Bool
== :: PlacementConstraint -> PlacementConstraint -> Bool
$c== :: PlacementConstraint -> PlacementConstraint -> Bool
Prelude.Eq, ReadPrec [PlacementConstraint]
ReadPrec PlacementConstraint
Int -> ReadS PlacementConstraint
ReadS [PlacementConstraint]
(Int -> ReadS PlacementConstraint)
-> ReadS [PlacementConstraint]
-> ReadPrec PlacementConstraint
-> ReadPrec [PlacementConstraint]
-> Read PlacementConstraint
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PlacementConstraint]
$creadListPrec :: ReadPrec [PlacementConstraint]
readPrec :: ReadPrec PlacementConstraint
$creadPrec :: ReadPrec PlacementConstraint
readList :: ReadS [PlacementConstraint]
$creadList :: ReadS [PlacementConstraint]
readsPrec :: Int -> ReadS PlacementConstraint
$creadsPrec :: Int -> ReadS PlacementConstraint
Prelude.Read, Int -> PlacementConstraint -> ShowS
[PlacementConstraint] -> ShowS
PlacementConstraint -> String
(Int -> PlacementConstraint -> ShowS)
-> (PlacementConstraint -> String)
-> ([PlacementConstraint] -> ShowS)
-> Show PlacementConstraint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PlacementConstraint] -> ShowS
$cshowList :: [PlacementConstraint] -> ShowS
show :: PlacementConstraint -> String
$cshow :: PlacementConstraint -> String
showsPrec :: Int -> PlacementConstraint -> ShowS
$cshowsPrec :: Int -> PlacementConstraint -> ShowS
Prelude.Show, (forall x. PlacementConstraint -> Rep PlacementConstraint x)
-> (forall x. Rep PlacementConstraint x -> PlacementConstraint)
-> Generic PlacementConstraint
forall x. Rep PlacementConstraint x -> PlacementConstraint
forall x. PlacementConstraint -> Rep PlacementConstraint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PlacementConstraint x -> PlacementConstraint
$cfrom :: forall x. PlacementConstraint -> Rep PlacementConstraint x
Prelude.Generic)

-- |
-- Create a value of 'PlacementConstraint' 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:
--
-- 'expression', 'placementConstraint_expression' - A cluster query language expression to apply to the constraint. The
-- expression can have a maximum length of 2000 characters. You can\'t
-- specify an expression if the constraint type is @distinctInstance@. For
-- more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html Cluster query language>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- 'type'', 'placementConstraint_type' - The type of constraint. Use @distinctInstance@ to ensure that each task
-- in a particular group is running on a different container instance. Use
-- @memberOf@ to restrict the selection to a group of valid candidates.
newPlacementConstraint ::
  PlacementConstraint
newPlacementConstraint :: PlacementConstraint
newPlacementConstraint =
  PlacementConstraint' :: Maybe Text -> Maybe PlacementConstraintType -> PlacementConstraint
PlacementConstraint'
    { $sel:expression:PlacementConstraint' :: Maybe Text
expression = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':PlacementConstraint' :: Maybe PlacementConstraintType
type' = Maybe PlacementConstraintType
forall a. Maybe a
Prelude.Nothing
    }

-- | A cluster query language expression to apply to the constraint. The
-- expression can have a maximum length of 2000 characters. You can\'t
-- specify an expression if the constraint type is @distinctInstance@. For
-- more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html Cluster query language>
-- in the /Amazon Elastic Container Service Developer Guide/.
placementConstraint_expression :: Lens.Lens' PlacementConstraint (Prelude.Maybe Prelude.Text)
placementConstraint_expression :: (Maybe Text -> f (Maybe Text))
-> PlacementConstraint -> f PlacementConstraint
placementConstraint_expression = (PlacementConstraint -> Maybe Text)
-> (PlacementConstraint -> Maybe Text -> PlacementConstraint)
-> Lens
     PlacementConstraint PlacementConstraint (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlacementConstraint' {Maybe Text
expression :: Maybe Text
$sel:expression:PlacementConstraint' :: PlacementConstraint -> Maybe Text
expression} -> Maybe Text
expression) (\s :: PlacementConstraint
s@PlacementConstraint' {} Maybe Text
a -> PlacementConstraint
s {$sel:expression:PlacementConstraint' :: Maybe Text
expression = Maybe Text
a} :: PlacementConstraint)

-- | The type of constraint. Use @distinctInstance@ to ensure that each task
-- in a particular group is running on a different container instance. Use
-- @memberOf@ to restrict the selection to a group of valid candidates.
placementConstraint_type :: Lens.Lens' PlacementConstraint (Prelude.Maybe PlacementConstraintType)
placementConstraint_type :: (Maybe PlacementConstraintType
 -> f (Maybe PlacementConstraintType))
-> PlacementConstraint -> f PlacementConstraint
placementConstraint_type = (PlacementConstraint -> Maybe PlacementConstraintType)
-> (PlacementConstraint
    -> Maybe PlacementConstraintType -> PlacementConstraint)
-> Lens
     PlacementConstraint
     PlacementConstraint
     (Maybe PlacementConstraintType)
     (Maybe PlacementConstraintType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlacementConstraint' {Maybe PlacementConstraintType
type' :: Maybe PlacementConstraintType
$sel:type':PlacementConstraint' :: PlacementConstraint -> Maybe PlacementConstraintType
type'} -> Maybe PlacementConstraintType
type') (\s :: PlacementConstraint
s@PlacementConstraint' {} Maybe PlacementConstraintType
a -> PlacementConstraint
s {$sel:type':PlacementConstraint' :: Maybe PlacementConstraintType
type' = Maybe PlacementConstraintType
a} :: PlacementConstraint)

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

instance Prelude.Hashable PlacementConstraint

instance Prelude.NFData PlacementConstraint

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