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

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

-- | An attribute is a name-value pair associated with an Amazon ECS object.
-- Attributes enable you to extend the Amazon ECS data model by adding
-- custom metadata to your resources. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement-constraints.html#attributes Attributes>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- /See:/ 'newAttribute' smart constructor.
data Attribute = Attribute'
  { -- | The ID of the target. You can specify the short form ID for a resource
    -- or the full Amazon Resource Name (ARN).
    Attribute -> Maybe Text
targetId :: Prelude.Maybe Prelude.Text,
    -- | The value of the attribute. The @value@ must contain between 1 and 128
    -- characters and may contain letters (uppercase and lowercase), numbers,
    -- hyphens, underscores, periods, at signs (\@), forward slashes, back
    -- slashes, colons, or spaces. The value cannot contain any leading or
    -- trailing whitespace.
    Attribute -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The type of the target with which to attach the attribute. This
    -- parameter is required if you use the short form ID for a resource
    -- instead of the full ARN.
    Attribute -> Maybe TargetType
targetType :: Prelude.Maybe TargetType,
    -- | The name of the attribute. The @name@ must contain between 1 and 128
    -- characters and name may contain letters (uppercase and lowercase),
    -- numbers, hyphens, underscores, forward slashes, back slashes, or
    -- periods.
    Attribute -> Text
name :: Prelude.Text
  }
  deriving (Attribute -> Attribute -> Bool
(Attribute -> Attribute -> Bool)
-> (Attribute -> Attribute -> Bool) -> Eq Attribute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Attribute -> Attribute -> Bool
$c/= :: Attribute -> Attribute -> Bool
== :: Attribute -> Attribute -> Bool
$c== :: Attribute -> Attribute -> Bool
Prelude.Eq, ReadPrec [Attribute]
ReadPrec Attribute
Int -> ReadS Attribute
ReadS [Attribute]
(Int -> ReadS Attribute)
-> ReadS [Attribute]
-> ReadPrec Attribute
-> ReadPrec [Attribute]
-> Read Attribute
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Attribute]
$creadListPrec :: ReadPrec [Attribute]
readPrec :: ReadPrec Attribute
$creadPrec :: ReadPrec Attribute
readList :: ReadS [Attribute]
$creadList :: ReadS [Attribute]
readsPrec :: Int -> ReadS Attribute
$creadsPrec :: Int -> ReadS Attribute
Prelude.Read, Int -> Attribute -> ShowS
[Attribute] -> ShowS
Attribute -> String
(Int -> Attribute -> ShowS)
-> (Attribute -> String)
-> ([Attribute] -> ShowS)
-> Show Attribute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Attribute] -> ShowS
$cshowList :: [Attribute] -> ShowS
show :: Attribute -> String
$cshow :: Attribute -> String
showsPrec :: Int -> Attribute -> ShowS
$cshowsPrec :: Int -> Attribute -> ShowS
Prelude.Show, (forall x. Attribute -> Rep Attribute x)
-> (forall x. Rep Attribute x -> Attribute) -> Generic Attribute
forall x. Rep Attribute x -> Attribute
forall x. Attribute -> Rep Attribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Attribute x -> Attribute
$cfrom :: forall x. Attribute -> Rep Attribute x
Prelude.Generic)

-- |
-- Create a value of 'Attribute' 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:
--
-- 'targetId', 'attribute_targetId' - The ID of the target. You can specify the short form ID for a resource
-- or the full Amazon Resource Name (ARN).
--
-- 'value', 'attribute_value' - The value of the attribute. The @value@ must contain between 1 and 128
-- characters and may contain letters (uppercase and lowercase), numbers,
-- hyphens, underscores, periods, at signs (\@), forward slashes, back
-- slashes, colons, or spaces. The value cannot contain any leading or
-- trailing whitespace.
--
-- 'targetType', 'attribute_targetType' - The type of the target with which to attach the attribute. This
-- parameter is required if you use the short form ID for a resource
-- instead of the full ARN.
--
-- 'name', 'attribute_name' - The name of the attribute. The @name@ must contain between 1 and 128
-- characters and name may contain letters (uppercase and lowercase),
-- numbers, hyphens, underscores, forward slashes, back slashes, or
-- periods.
newAttribute ::
  -- | 'name'
  Prelude.Text ->
  Attribute
newAttribute :: Text -> Attribute
newAttribute Text
pName_ =
  Attribute' :: Maybe Text -> Maybe Text -> Maybe TargetType -> Text -> Attribute
Attribute'
    { $sel:targetId:Attribute' :: Maybe Text
targetId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:value:Attribute' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:targetType:Attribute' :: Maybe TargetType
targetType = Maybe TargetType
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Attribute' :: Text
name = Text
pName_
    }

-- | The ID of the target. You can specify the short form ID for a resource
-- or the full Amazon Resource Name (ARN).
attribute_targetId :: Lens.Lens' Attribute (Prelude.Maybe Prelude.Text)
attribute_targetId :: (Maybe Text -> f (Maybe Text)) -> Attribute -> f Attribute
attribute_targetId = (Attribute -> Maybe Text)
-> (Attribute -> Maybe Text -> Attribute)
-> Lens Attribute Attribute (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Attribute' {Maybe Text
targetId :: Maybe Text
$sel:targetId:Attribute' :: Attribute -> Maybe Text
targetId} -> Maybe Text
targetId) (\s :: Attribute
s@Attribute' {} Maybe Text
a -> Attribute
s {$sel:targetId:Attribute' :: Maybe Text
targetId = Maybe Text
a} :: Attribute)

-- | The value of the attribute. The @value@ must contain between 1 and 128
-- characters and may contain letters (uppercase and lowercase), numbers,
-- hyphens, underscores, periods, at signs (\@), forward slashes, back
-- slashes, colons, or spaces. The value cannot contain any leading or
-- trailing whitespace.
attribute_value :: Lens.Lens' Attribute (Prelude.Maybe Prelude.Text)
attribute_value :: (Maybe Text -> f (Maybe Text)) -> Attribute -> f Attribute
attribute_value = (Attribute -> Maybe Text)
-> (Attribute -> Maybe Text -> Attribute)
-> Lens Attribute Attribute (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Attribute' {Maybe Text
value :: Maybe Text
$sel:value:Attribute' :: Attribute -> Maybe Text
value} -> Maybe Text
value) (\s :: Attribute
s@Attribute' {} Maybe Text
a -> Attribute
s {$sel:value:Attribute' :: Maybe Text
value = Maybe Text
a} :: Attribute)

-- | The type of the target with which to attach the attribute. This
-- parameter is required if you use the short form ID for a resource
-- instead of the full ARN.
attribute_targetType :: Lens.Lens' Attribute (Prelude.Maybe TargetType)
attribute_targetType :: (Maybe TargetType -> f (Maybe TargetType))
-> Attribute -> f Attribute
attribute_targetType = (Attribute -> Maybe TargetType)
-> (Attribute -> Maybe TargetType -> Attribute)
-> Lens Attribute Attribute (Maybe TargetType) (Maybe TargetType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Attribute' {Maybe TargetType
targetType :: Maybe TargetType
$sel:targetType:Attribute' :: Attribute -> Maybe TargetType
targetType} -> Maybe TargetType
targetType) (\s :: Attribute
s@Attribute' {} Maybe TargetType
a -> Attribute
s {$sel:targetType:Attribute' :: Maybe TargetType
targetType = Maybe TargetType
a} :: Attribute)

-- | The name of the attribute. The @name@ must contain between 1 and 128
-- characters and name may contain letters (uppercase and lowercase),
-- numbers, hyphens, underscores, forward slashes, back slashes, or
-- periods.
attribute_name :: Lens.Lens' Attribute Prelude.Text
attribute_name :: (Text -> f Text) -> Attribute -> f Attribute
attribute_name = (Attribute -> Text)
-> (Attribute -> Text -> Attribute)
-> Lens Attribute Attribute Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Attribute' {Text
name :: Text
$sel:name:Attribute' :: Attribute -> Text
name} -> Text
name) (\s :: Attribute
s@Attribute' {} Text
a -> Attribute
s {$sel:name:Attribute' :: Text
name = Text
a} :: Attribute)

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

instance Prelude.Hashable Attribute

instance Prelude.NFData Attribute

instance Core.ToJSON Attribute where
  toJSON :: Attribute -> Value
toJSON Attribute' {Maybe Text
Maybe TargetType
Text
name :: Text
targetType :: Maybe TargetType
value :: Maybe Text
targetId :: Maybe Text
$sel:name:Attribute' :: Attribute -> Text
$sel:targetType:Attribute' :: Attribute -> Maybe TargetType
$sel:value:Attribute' :: Attribute -> Maybe Text
$sel:targetId:Attribute' :: Attribute -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"targetId" 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
targetId,
            (Text
"value" 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
value,
            (Text
"targetType" Text -> TargetType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TargetType -> Pair) -> Maybe TargetType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TargetType
targetType,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )