{-# 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.CloudDirectory.Types.TypedLinkSpecifier
-- 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.CloudDirectory.Types.TypedLinkSpecifier where

import Amazonka.CloudDirectory.Types.AttributeNameAndValue
import Amazonka.CloudDirectory.Types.ObjectReference
import Amazonka.CloudDirectory.Types.TypedLinkSchemaAndFacetName
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains all the information that is used to uniquely identify a typed
-- link. The parameters discussed in this topic are used to uniquely
-- specify the typed link being operated on. The AttachTypedLink API
-- returns a typed link specifier while the DetachTypedLink API accepts one
-- as input. Similarly, the ListIncomingTypedLinks and
-- ListOutgoingTypedLinks API operations provide typed link specifiers as
-- output. You can also construct a typed link specifier from scratch.
--
-- /See:/ 'newTypedLinkSpecifier' smart constructor.
data TypedLinkSpecifier = TypedLinkSpecifier'
  { -- | Identifies the typed link facet that is associated with the typed link.
    TypedLinkSpecifier -> TypedLinkSchemaAndFacetName
typedLinkFacet :: TypedLinkSchemaAndFacetName,
    -- | Identifies the source object that the typed link will attach to.
    TypedLinkSpecifier -> ObjectReference
sourceObjectReference :: ObjectReference,
    -- | Identifies the target object that the typed link will attach to.
    TypedLinkSpecifier -> ObjectReference
targetObjectReference :: ObjectReference,
    -- | Identifies the attribute value to update.
    TypedLinkSpecifier -> [AttributeNameAndValue]
identityAttributeValues :: [AttributeNameAndValue]
  }
  deriving (TypedLinkSpecifier -> TypedLinkSpecifier -> Bool
(TypedLinkSpecifier -> TypedLinkSpecifier -> Bool)
-> (TypedLinkSpecifier -> TypedLinkSpecifier -> Bool)
-> Eq TypedLinkSpecifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TypedLinkSpecifier -> TypedLinkSpecifier -> Bool
$c/= :: TypedLinkSpecifier -> TypedLinkSpecifier -> Bool
== :: TypedLinkSpecifier -> TypedLinkSpecifier -> Bool
$c== :: TypedLinkSpecifier -> TypedLinkSpecifier -> Bool
Prelude.Eq, ReadPrec [TypedLinkSpecifier]
ReadPrec TypedLinkSpecifier
Int -> ReadS TypedLinkSpecifier
ReadS [TypedLinkSpecifier]
(Int -> ReadS TypedLinkSpecifier)
-> ReadS [TypedLinkSpecifier]
-> ReadPrec TypedLinkSpecifier
-> ReadPrec [TypedLinkSpecifier]
-> Read TypedLinkSpecifier
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TypedLinkSpecifier]
$creadListPrec :: ReadPrec [TypedLinkSpecifier]
readPrec :: ReadPrec TypedLinkSpecifier
$creadPrec :: ReadPrec TypedLinkSpecifier
readList :: ReadS [TypedLinkSpecifier]
$creadList :: ReadS [TypedLinkSpecifier]
readsPrec :: Int -> ReadS TypedLinkSpecifier
$creadsPrec :: Int -> ReadS TypedLinkSpecifier
Prelude.Read, Int -> TypedLinkSpecifier -> ShowS
[TypedLinkSpecifier] -> ShowS
TypedLinkSpecifier -> String
(Int -> TypedLinkSpecifier -> ShowS)
-> (TypedLinkSpecifier -> String)
-> ([TypedLinkSpecifier] -> ShowS)
-> Show TypedLinkSpecifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TypedLinkSpecifier] -> ShowS
$cshowList :: [TypedLinkSpecifier] -> ShowS
show :: TypedLinkSpecifier -> String
$cshow :: TypedLinkSpecifier -> String
showsPrec :: Int -> TypedLinkSpecifier -> ShowS
$cshowsPrec :: Int -> TypedLinkSpecifier -> ShowS
Prelude.Show, (forall x. TypedLinkSpecifier -> Rep TypedLinkSpecifier x)
-> (forall x. Rep TypedLinkSpecifier x -> TypedLinkSpecifier)
-> Generic TypedLinkSpecifier
forall x. Rep TypedLinkSpecifier x -> TypedLinkSpecifier
forall x. TypedLinkSpecifier -> Rep TypedLinkSpecifier x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TypedLinkSpecifier x -> TypedLinkSpecifier
$cfrom :: forall x. TypedLinkSpecifier -> Rep TypedLinkSpecifier x
Prelude.Generic)

-- |
-- Create a value of 'TypedLinkSpecifier' 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:
--
-- 'typedLinkFacet', 'typedLinkSpecifier_typedLinkFacet' - Identifies the typed link facet that is associated with the typed link.
--
-- 'sourceObjectReference', 'typedLinkSpecifier_sourceObjectReference' - Identifies the source object that the typed link will attach to.
--
-- 'targetObjectReference', 'typedLinkSpecifier_targetObjectReference' - Identifies the target object that the typed link will attach to.
--
-- 'identityAttributeValues', 'typedLinkSpecifier_identityAttributeValues' - Identifies the attribute value to update.
newTypedLinkSpecifier ::
  -- | 'typedLinkFacet'
  TypedLinkSchemaAndFacetName ->
  -- | 'sourceObjectReference'
  ObjectReference ->
  -- | 'targetObjectReference'
  ObjectReference ->
  TypedLinkSpecifier
newTypedLinkSpecifier :: TypedLinkSchemaAndFacetName
-> ObjectReference -> ObjectReference -> TypedLinkSpecifier
newTypedLinkSpecifier
  TypedLinkSchemaAndFacetName
pTypedLinkFacet_
  ObjectReference
pSourceObjectReference_
  ObjectReference
pTargetObjectReference_ =
    TypedLinkSpecifier' :: TypedLinkSchemaAndFacetName
-> ObjectReference
-> ObjectReference
-> [AttributeNameAndValue]
-> TypedLinkSpecifier
TypedLinkSpecifier'
      { $sel:typedLinkFacet:TypedLinkSpecifier' :: TypedLinkSchemaAndFacetName
typedLinkFacet =
          TypedLinkSchemaAndFacetName
pTypedLinkFacet_,
        $sel:sourceObjectReference:TypedLinkSpecifier' :: ObjectReference
sourceObjectReference = ObjectReference
pSourceObjectReference_,
        $sel:targetObjectReference:TypedLinkSpecifier' :: ObjectReference
targetObjectReference = ObjectReference
pTargetObjectReference_,
        $sel:identityAttributeValues:TypedLinkSpecifier' :: [AttributeNameAndValue]
identityAttributeValues = [AttributeNameAndValue]
forall a. Monoid a => a
Prelude.mempty
      }

-- | Identifies the typed link facet that is associated with the typed link.
typedLinkSpecifier_typedLinkFacet :: Lens.Lens' TypedLinkSpecifier TypedLinkSchemaAndFacetName
typedLinkSpecifier_typedLinkFacet :: (TypedLinkSchemaAndFacetName -> f TypedLinkSchemaAndFacetName)
-> TypedLinkSpecifier -> f TypedLinkSpecifier
typedLinkSpecifier_typedLinkFacet = (TypedLinkSpecifier -> TypedLinkSchemaAndFacetName)
-> (TypedLinkSpecifier
    -> TypedLinkSchemaAndFacetName -> TypedLinkSpecifier)
-> Lens
     TypedLinkSpecifier
     TypedLinkSpecifier
     TypedLinkSchemaAndFacetName
     TypedLinkSchemaAndFacetName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TypedLinkSpecifier' {TypedLinkSchemaAndFacetName
typedLinkFacet :: TypedLinkSchemaAndFacetName
$sel:typedLinkFacet:TypedLinkSpecifier' :: TypedLinkSpecifier -> TypedLinkSchemaAndFacetName
typedLinkFacet} -> TypedLinkSchemaAndFacetName
typedLinkFacet) (\s :: TypedLinkSpecifier
s@TypedLinkSpecifier' {} TypedLinkSchemaAndFacetName
a -> TypedLinkSpecifier
s {$sel:typedLinkFacet:TypedLinkSpecifier' :: TypedLinkSchemaAndFacetName
typedLinkFacet = TypedLinkSchemaAndFacetName
a} :: TypedLinkSpecifier)

-- | Identifies the source object that the typed link will attach to.
typedLinkSpecifier_sourceObjectReference :: Lens.Lens' TypedLinkSpecifier ObjectReference
typedLinkSpecifier_sourceObjectReference :: (ObjectReference -> f ObjectReference)
-> TypedLinkSpecifier -> f TypedLinkSpecifier
typedLinkSpecifier_sourceObjectReference = (TypedLinkSpecifier -> ObjectReference)
-> (TypedLinkSpecifier -> ObjectReference -> TypedLinkSpecifier)
-> Lens
     TypedLinkSpecifier
     TypedLinkSpecifier
     ObjectReference
     ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TypedLinkSpecifier' {ObjectReference
sourceObjectReference :: ObjectReference
$sel:sourceObjectReference:TypedLinkSpecifier' :: TypedLinkSpecifier -> ObjectReference
sourceObjectReference} -> ObjectReference
sourceObjectReference) (\s :: TypedLinkSpecifier
s@TypedLinkSpecifier' {} ObjectReference
a -> TypedLinkSpecifier
s {$sel:sourceObjectReference:TypedLinkSpecifier' :: ObjectReference
sourceObjectReference = ObjectReference
a} :: TypedLinkSpecifier)

-- | Identifies the target object that the typed link will attach to.
typedLinkSpecifier_targetObjectReference :: Lens.Lens' TypedLinkSpecifier ObjectReference
typedLinkSpecifier_targetObjectReference :: (ObjectReference -> f ObjectReference)
-> TypedLinkSpecifier -> f TypedLinkSpecifier
typedLinkSpecifier_targetObjectReference = (TypedLinkSpecifier -> ObjectReference)
-> (TypedLinkSpecifier -> ObjectReference -> TypedLinkSpecifier)
-> Lens
     TypedLinkSpecifier
     TypedLinkSpecifier
     ObjectReference
     ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TypedLinkSpecifier' {ObjectReference
targetObjectReference :: ObjectReference
$sel:targetObjectReference:TypedLinkSpecifier' :: TypedLinkSpecifier -> ObjectReference
targetObjectReference} -> ObjectReference
targetObjectReference) (\s :: TypedLinkSpecifier
s@TypedLinkSpecifier' {} ObjectReference
a -> TypedLinkSpecifier
s {$sel:targetObjectReference:TypedLinkSpecifier' :: ObjectReference
targetObjectReference = ObjectReference
a} :: TypedLinkSpecifier)

-- | Identifies the attribute value to update.
typedLinkSpecifier_identityAttributeValues :: Lens.Lens' TypedLinkSpecifier [AttributeNameAndValue]
typedLinkSpecifier_identityAttributeValues :: ([AttributeNameAndValue] -> f [AttributeNameAndValue])
-> TypedLinkSpecifier -> f TypedLinkSpecifier
typedLinkSpecifier_identityAttributeValues = (TypedLinkSpecifier -> [AttributeNameAndValue])
-> (TypedLinkSpecifier
    -> [AttributeNameAndValue] -> TypedLinkSpecifier)
-> Lens
     TypedLinkSpecifier
     TypedLinkSpecifier
     [AttributeNameAndValue]
     [AttributeNameAndValue]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TypedLinkSpecifier' {[AttributeNameAndValue]
identityAttributeValues :: [AttributeNameAndValue]
$sel:identityAttributeValues:TypedLinkSpecifier' :: TypedLinkSpecifier -> [AttributeNameAndValue]
identityAttributeValues} -> [AttributeNameAndValue]
identityAttributeValues) (\s :: TypedLinkSpecifier
s@TypedLinkSpecifier' {} [AttributeNameAndValue]
a -> TypedLinkSpecifier
s {$sel:identityAttributeValues:TypedLinkSpecifier' :: [AttributeNameAndValue]
identityAttributeValues = [AttributeNameAndValue]
a} :: TypedLinkSpecifier) (([AttributeNameAndValue] -> f [AttributeNameAndValue])
 -> TypedLinkSpecifier -> f TypedLinkSpecifier)
-> (([AttributeNameAndValue] -> f [AttributeNameAndValue])
    -> [AttributeNameAndValue] -> f [AttributeNameAndValue])
-> ([AttributeNameAndValue] -> f [AttributeNameAndValue])
-> TypedLinkSpecifier
-> f TypedLinkSpecifier
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([AttributeNameAndValue] -> f [AttributeNameAndValue])
-> [AttributeNameAndValue] -> f [AttributeNameAndValue]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON TypedLinkSpecifier where
  parseJSON :: Value -> Parser TypedLinkSpecifier
parseJSON =
    String
-> (Object -> Parser TypedLinkSpecifier)
-> Value
-> Parser TypedLinkSpecifier
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TypedLinkSpecifier"
      ( \Object
x ->
          TypedLinkSchemaAndFacetName
-> ObjectReference
-> ObjectReference
-> [AttributeNameAndValue]
-> TypedLinkSpecifier
TypedLinkSpecifier'
            (TypedLinkSchemaAndFacetName
 -> ObjectReference
 -> ObjectReference
 -> [AttributeNameAndValue]
 -> TypedLinkSpecifier)
-> Parser TypedLinkSchemaAndFacetName
-> Parser
     (ObjectReference
      -> ObjectReference
      -> [AttributeNameAndValue]
      -> TypedLinkSpecifier)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser TypedLinkSchemaAndFacetName
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"TypedLinkFacet")
            Parser
  (ObjectReference
   -> ObjectReference
   -> [AttributeNameAndValue]
   -> TypedLinkSpecifier)
-> Parser ObjectReference
-> Parser
     (ObjectReference -> [AttributeNameAndValue] -> TypedLinkSpecifier)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ObjectReference
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"SourceObjectReference")
            Parser
  (ObjectReference -> [AttributeNameAndValue] -> TypedLinkSpecifier)
-> Parser ObjectReference
-> Parser ([AttributeNameAndValue] -> TypedLinkSpecifier)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ObjectReference
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"TargetObjectReference")
            Parser ([AttributeNameAndValue] -> TypedLinkSpecifier)
-> Parser [AttributeNameAndValue] -> Parser TypedLinkSpecifier
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe [AttributeNameAndValue])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"IdentityAttributeValues"
                            Parser (Maybe [AttributeNameAndValue])
-> [AttributeNameAndValue] -> Parser [AttributeNameAndValue]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [AttributeNameAndValue]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable TypedLinkSpecifier

instance Prelude.NFData TypedLinkSpecifier

instance Core.ToJSON TypedLinkSpecifier where
  toJSON :: TypedLinkSpecifier -> Value
toJSON TypedLinkSpecifier' {[AttributeNameAndValue]
ObjectReference
TypedLinkSchemaAndFacetName
identityAttributeValues :: [AttributeNameAndValue]
targetObjectReference :: ObjectReference
sourceObjectReference :: ObjectReference
typedLinkFacet :: TypedLinkSchemaAndFacetName
$sel:identityAttributeValues:TypedLinkSpecifier' :: TypedLinkSpecifier -> [AttributeNameAndValue]
$sel:targetObjectReference:TypedLinkSpecifier' :: TypedLinkSpecifier -> ObjectReference
$sel:sourceObjectReference:TypedLinkSpecifier' :: TypedLinkSpecifier -> ObjectReference
$sel:typedLinkFacet:TypedLinkSpecifier' :: TypedLinkSpecifier -> TypedLinkSchemaAndFacetName
..} =
    [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
"TypedLinkFacet" Text -> TypedLinkSchemaAndFacetName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= TypedLinkSchemaAndFacetName
typedLinkFacet),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"SourceObjectReference"
                  Text -> ObjectReference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ObjectReference
sourceObjectReference
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"TargetObjectReference"
                  Text -> ObjectReference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ObjectReference
targetObjectReference
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"IdentityAttributeValues"
                  Text -> [AttributeNameAndValue] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [AttributeNameAndValue]
identityAttributeValues
              )
          ]
      )