{-# 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.CloudWatchEvents.Types.PlacementConstraint
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudWatchEvents.Types.PlacementConstraint where

import Amazonka.CloudWatchEvents.Types.PlacementConstraintType
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | An object representing a constraint on task placement. To learn more,
-- see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement-constraints.html Task Placement Constraints>
-- in the Amazon Elastic Container Service Developer Guide.
--
-- /See:/ 'newPlacementConstraint' smart constructor.
data PlacementConstraint = PlacementConstraint'
  { -- | A cluster query language expression to apply to the constraint. You
    -- cannot specify an expression if the constraint type is
    -- @distinctInstance@. To learn more, 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
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]
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
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. 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. You
-- cannot specify an expression if the constraint type is
-- @distinctInstance@. To learn more, 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'
    { $sel:expression:PlacementConstraint' :: Maybe Text
expression = forall a. Maybe a
Prelude.Nothing,
      $sel:type':PlacementConstraint' :: Maybe PlacementConstraintType
type' = forall a. Maybe a
Prelude.Nothing
    }

-- | A cluster query language expression to apply to the constraint. You
-- cannot specify an expression if the constraint type is
-- @distinctInstance@. To learn more, 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 :: Lens' PlacementConstraint (Maybe Text)
placementConstraint_expression = 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 :: Lens' PlacementConstraint (Maybe PlacementConstraintType)
placementConstraint_type = 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 Data.FromJSON PlacementConstraint where
  parseJSON :: Value -> Parser PlacementConstraint
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PlacementConstraint"
      ( \Object
x ->
          Maybe Text -> Maybe PlacementConstraintType -> PlacementConstraint
PlacementConstraint'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"expression")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"type")
      )

instance Prelude.Hashable PlacementConstraint where
  hashWithSalt :: Int -> PlacementConstraint -> Int
hashWithSalt Int
_salt PlacementConstraint' {Maybe Text
Maybe PlacementConstraintType
type' :: Maybe PlacementConstraintType
expression :: Maybe Text
$sel:type':PlacementConstraint' :: PlacementConstraint -> Maybe PlacementConstraintType
$sel:expression:PlacementConstraint' :: PlacementConstraint -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
expression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PlacementConstraintType
type'

instance Prelude.NFData PlacementConstraint where
  rnf :: PlacementConstraint -> ()
rnf PlacementConstraint' {Maybe Text
Maybe PlacementConstraintType
type' :: Maybe PlacementConstraintType
expression :: Maybe Text
$sel:type':PlacementConstraint' :: PlacementConstraint -> Maybe PlacementConstraintType
$sel:expression:PlacementConstraint' :: PlacementConstraint -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
expression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe PlacementConstraintType
type'

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"expression" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
expression,
            (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PlacementConstraintType
type'
          ]
      )