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

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

-- | An object representing a constraint on task placement in the task
-- definition. 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/.
--
-- Task placement constraints are not supported for tasks run on Fargate.
--
-- /See:/ 'newTaskDefinitionPlacementConstraint' smart constructor.
data TaskDefinitionPlacementConstraint = TaskDefinitionPlacementConstraint'
  { -- | A cluster query language expression to apply to the constraint. 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/.
    TaskDefinitionPlacementConstraint -> Maybe Text
expression :: Prelude.Maybe Prelude.Text,
    -- | The type of constraint. The @MemberOf@ constraint restricts selection to
    -- be from a group of valid candidates.
    TaskDefinitionPlacementConstraint
-> Maybe TaskDefinitionPlacementConstraintType
type' :: Prelude.Maybe TaskDefinitionPlacementConstraintType
  }
  deriving (TaskDefinitionPlacementConstraint
-> TaskDefinitionPlacementConstraint -> Bool
(TaskDefinitionPlacementConstraint
 -> TaskDefinitionPlacementConstraint -> Bool)
-> (TaskDefinitionPlacementConstraint
    -> TaskDefinitionPlacementConstraint -> Bool)
-> Eq TaskDefinitionPlacementConstraint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TaskDefinitionPlacementConstraint
-> TaskDefinitionPlacementConstraint -> Bool
$c/= :: TaskDefinitionPlacementConstraint
-> TaskDefinitionPlacementConstraint -> Bool
== :: TaskDefinitionPlacementConstraint
-> TaskDefinitionPlacementConstraint -> Bool
$c== :: TaskDefinitionPlacementConstraint
-> TaskDefinitionPlacementConstraint -> Bool
Prelude.Eq, ReadPrec [TaskDefinitionPlacementConstraint]
ReadPrec TaskDefinitionPlacementConstraint
Int -> ReadS TaskDefinitionPlacementConstraint
ReadS [TaskDefinitionPlacementConstraint]
(Int -> ReadS TaskDefinitionPlacementConstraint)
-> ReadS [TaskDefinitionPlacementConstraint]
-> ReadPrec TaskDefinitionPlacementConstraint
-> ReadPrec [TaskDefinitionPlacementConstraint]
-> Read TaskDefinitionPlacementConstraint
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TaskDefinitionPlacementConstraint]
$creadListPrec :: ReadPrec [TaskDefinitionPlacementConstraint]
readPrec :: ReadPrec TaskDefinitionPlacementConstraint
$creadPrec :: ReadPrec TaskDefinitionPlacementConstraint
readList :: ReadS [TaskDefinitionPlacementConstraint]
$creadList :: ReadS [TaskDefinitionPlacementConstraint]
readsPrec :: Int -> ReadS TaskDefinitionPlacementConstraint
$creadsPrec :: Int -> ReadS TaskDefinitionPlacementConstraint
Prelude.Read, Int -> TaskDefinitionPlacementConstraint -> ShowS
[TaskDefinitionPlacementConstraint] -> ShowS
TaskDefinitionPlacementConstraint -> String
(Int -> TaskDefinitionPlacementConstraint -> ShowS)
-> (TaskDefinitionPlacementConstraint -> String)
-> ([TaskDefinitionPlacementConstraint] -> ShowS)
-> Show TaskDefinitionPlacementConstraint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TaskDefinitionPlacementConstraint] -> ShowS
$cshowList :: [TaskDefinitionPlacementConstraint] -> ShowS
show :: TaskDefinitionPlacementConstraint -> String
$cshow :: TaskDefinitionPlacementConstraint -> String
showsPrec :: Int -> TaskDefinitionPlacementConstraint -> ShowS
$cshowsPrec :: Int -> TaskDefinitionPlacementConstraint -> ShowS
Prelude.Show, (forall x.
 TaskDefinitionPlacementConstraint
 -> Rep TaskDefinitionPlacementConstraint x)
-> (forall x.
    Rep TaskDefinitionPlacementConstraint x
    -> TaskDefinitionPlacementConstraint)
-> Generic TaskDefinitionPlacementConstraint
forall x.
Rep TaskDefinitionPlacementConstraint x
-> TaskDefinitionPlacementConstraint
forall x.
TaskDefinitionPlacementConstraint
-> Rep TaskDefinitionPlacementConstraint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TaskDefinitionPlacementConstraint x
-> TaskDefinitionPlacementConstraint
$cfrom :: forall x.
TaskDefinitionPlacementConstraint
-> Rep TaskDefinitionPlacementConstraint x
Prelude.Generic)

-- |
-- Create a value of 'TaskDefinitionPlacementConstraint' 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', 'taskDefinitionPlacementConstraint_expression' - A cluster query language expression to apply to the constraint. 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'', 'taskDefinitionPlacementConstraint_type' - The type of constraint. The @MemberOf@ constraint restricts selection to
-- be from a group of valid candidates.
newTaskDefinitionPlacementConstraint ::
  TaskDefinitionPlacementConstraint
newTaskDefinitionPlacementConstraint :: TaskDefinitionPlacementConstraint
newTaskDefinitionPlacementConstraint =
  TaskDefinitionPlacementConstraint' :: Maybe Text
-> Maybe TaskDefinitionPlacementConstraintType
-> TaskDefinitionPlacementConstraint
TaskDefinitionPlacementConstraint'
    { $sel:expression:TaskDefinitionPlacementConstraint' :: Maybe Text
expression =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':TaskDefinitionPlacementConstraint' :: Maybe TaskDefinitionPlacementConstraintType
type' = Maybe TaskDefinitionPlacementConstraintType
forall a. Maybe a
Prelude.Nothing
    }

-- | A cluster query language expression to apply to the constraint. 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/.
taskDefinitionPlacementConstraint_expression :: Lens.Lens' TaskDefinitionPlacementConstraint (Prelude.Maybe Prelude.Text)
taskDefinitionPlacementConstraint_expression :: (Maybe Text -> f (Maybe Text))
-> TaskDefinitionPlacementConstraint
-> f TaskDefinitionPlacementConstraint
taskDefinitionPlacementConstraint_expression = (TaskDefinitionPlacementConstraint -> Maybe Text)
-> (TaskDefinitionPlacementConstraint
    -> Maybe Text -> TaskDefinitionPlacementConstraint)
-> Lens
     TaskDefinitionPlacementConstraint
     TaskDefinitionPlacementConstraint
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TaskDefinitionPlacementConstraint' {Maybe Text
expression :: Maybe Text
$sel:expression:TaskDefinitionPlacementConstraint' :: TaskDefinitionPlacementConstraint -> Maybe Text
expression} -> Maybe Text
expression) (\s :: TaskDefinitionPlacementConstraint
s@TaskDefinitionPlacementConstraint' {} Maybe Text
a -> TaskDefinitionPlacementConstraint
s {$sel:expression:TaskDefinitionPlacementConstraint' :: Maybe Text
expression = Maybe Text
a} :: TaskDefinitionPlacementConstraint)

-- | The type of constraint. The @MemberOf@ constraint restricts selection to
-- be from a group of valid candidates.
taskDefinitionPlacementConstraint_type :: Lens.Lens' TaskDefinitionPlacementConstraint (Prelude.Maybe TaskDefinitionPlacementConstraintType)
taskDefinitionPlacementConstraint_type :: (Maybe TaskDefinitionPlacementConstraintType
 -> f (Maybe TaskDefinitionPlacementConstraintType))
-> TaskDefinitionPlacementConstraint
-> f TaskDefinitionPlacementConstraint
taskDefinitionPlacementConstraint_type = (TaskDefinitionPlacementConstraint
 -> Maybe TaskDefinitionPlacementConstraintType)
-> (TaskDefinitionPlacementConstraint
    -> Maybe TaskDefinitionPlacementConstraintType
    -> TaskDefinitionPlacementConstraint)
-> Lens
     TaskDefinitionPlacementConstraint
     TaskDefinitionPlacementConstraint
     (Maybe TaskDefinitionPlacementConstraintType)
     (Maybe TaskDefinitionPlacementConstraintType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TaskDefinitionPlacementConstraint' {Maybe TaskDefinitionPlacementConstraintType
type' :: Maybe TaskDefinitionPlacementConstraintType
$sel:type':TaskDefinitionPlacementConstraint' :: TaskDefinitionPlacementConstraint
-> Maybe TaskDefinitionPlacementConstraintType
type'} -> Maybe TaskDefinitionPlacementConstraintType
type') (\s :: TaskDefinitionPlacementConstraint
s@TaskDefinitionPlacementConstraint' {} Maybe TaskDefinitionPlacementConstraintType
a -> TaskDefinitionPlacementConstraint
s {$sel:type':TaskDefinitionPlacementConstraint' :: Maybe TaskDefinitionPlacementConstraintType
type' = Maybe TaskDefinitionPlacementConstraintType
a} :: TaskDefinitionPlacementConstraint)

instance
  Core.FromJSON
    TaskDefinitionPlacementConstraint
  where
  parseJSON :: Value -> Parser TaskDefinitionPlacementConstraint
parseJSON =
    String
-> (Object -> Parser TaskDefinitionPlacementConstraint)
-> Value
-> Parser TaskDefinitionPlacementConstraint
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TaskDefinitionPlacementConstraint"
      ( \Object
x ->
          Maybe Text
-> Maybe TaskDefinitionPlacementConstraintType
-> TaskDefinitionPlacementConstraint
TaskDefinitionPlacementConstraint'
            (Maybe Text
 -> Maybe TaskDefinitionPlacementConstraintType
 -> TaskDefinitionPlacementConstraint)
-> Parser (Maybe Text)
-> Parser
     (Maybe TaskDefinitionPlacementConstraintType
      -> TaskDefinitionPlacementConstraint)
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 TaskDefinitionPlacementConstraintType
   -> TaskDefinitionPlacementConstraint)
-> Parser (Maybe TaskDefinitionPlacementConstraintType)
-> Parser TaskDefinitionPlacementConstraint
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text -> Parser (Maybe TaskDefinitionPlacementConstraintType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"type")
      )

instance
  Prelude.Hashable
    TaskDefinitionPlacementConstraint

instance
  Prelude.NFData
    TaskDefinitionPlacementConstraint

instance
  Core.ToJSON
    TaskDefinitionPlacementConstraint
  where
  toJSON :: TaskDefinitionPlacementConstraint -> Value
toJSON TaskDefinitionPlacementConstraint' {Maybe Text
Maybe TaskDefinitionPlacementConstraintType
type' :: Maybe TaskDefinitionPlacementConstraintType
expression :: Maybe Text
$sel:type':TaskDefinitionPlacementConstraint' :: TaskDefinitionPlacementConstraint
-> Maybe TaskDefinitionPlacementConstraintType
$sel:expression:TaskDefinitionPlacementConstraint' :: TaskDefinitionPlacementConstraint -> 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 -> TaskDefinitionPlacementConstraintType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TaskDefinitionPlacementConstraintType -> Pair)
-> Maybe TaskDefinitionPlacementConstraintType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TaskDefinitionPlacementConstraintType
type'
          ]
      )