{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.AttachObject
-- 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)
--
-- Attaches an existing object to another object. An object can be accessed
-- in two ways:
--
-- 1.  Using the path
--
-- 2.  Using @ObjectIdentifier@
module Amazonka.CloudDirectory.AttachObject
  ( -- * Creating a Request
    AttachObject (..),
    newAttachObject,

    -- * Request Lenses
    attachObject_directoryArn,
    attachObject_parentReference,
    attachObject_childReference,
    attachObject_linkName,

    -- * Destructuring the Response
    AttachObjectResponse (..),
    newAttachObjectResponse,

    -- * Response Lenses
    attachObjectResponse_attachedObjectIdentifier,
    attachObjectResponse_httpStatus,
  )
where

import Amazonka.CloudDirectory.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAttachObject' smart constructor.
data AttachObject = AttachObject'
  { -- | Amazon Resource Name (ARN) that is associated with the Directory where
    -- both objects reside. For more information, see arns.
    AttachObject -> Text
directoryArn :: Prelude.Text,
    -- | The parent object reference.
    AttachObject -> ObjectReference
parentReference :: ObjectReference,
    -- | The child object reference to be attached to the object.
    AttachObject -> ObjectReference
childReference :: ObjectReference,
    -- | The link name with which the child object is attached to the parent.
    AttachObject -> Text
linkName :: Prelude.Text
  }
  deriving (AttachObject -> AttachObject -> Bool
(AttachObject -> AttachObject -> Bool)
-> (AttachObject -> AttachObject -> Bool) -> Eq AttachObject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachObject -> AttachObject -> Bool
$c/= :: AttachObject -> AttachObject -> Bool
== :: AttachObject -> AttachObject -> Bool
$c== :: AttachObject -> AttachObject -> Bool
Prelude.Eq, ReadPrec [AttachObject]
ReadPrec AttachObject
Int -> ReadS AttachObject
ReadS [AttachObject]
(Int -> ReadS AttachObject)
-> ReadS [AttachObject]
-> ReadPrec AttachObject
-> ReadPrec [AttachObject]
-> Read AttachObject
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachObject]
$creadListPrec :: ReadPrec [AttachObject]
readPrec :: ReadPrec AttachObject
$creadPrec :: ReadPrec AttachObject
readList :: ReadS [AttachObject]
$creadList :: ReadS [AttachObject]
readsPrec :: Int -> ReadS AttachObject
$creadsPrec :: Int -> ReadS AttachObject
Prelude.Read, Int -> AttachObject -> ShowS
[AttachObject] -> ShowS
AttachObject -> String
(Int -> AttachObject -> ShowS)
-> (AttachObject -> String)
-> ([AttachObject] -> ShowS)
-> Show AttachObject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachObject] -> ShowS
$cshowList :: [AttachObject] -> ShowS
show :: AttachObject -> String
$cshow :: AttachObject -> String
showsPrec :: Int -> AttachObject -> ShowS
$cshowsPrec :: Int -> AttachObject -> ShowS
Prelude.Show, (forall x. AttachObject -> Rep AttachObject x)
-> (forall x. Rep AttachObject x -> AttachObject)
-> Generic AttachObject
forall x. Rep AttachObject x -> AttachObject
forall x. AttachObject -> Rep AttachObject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachObject x -> AttachObject
$cfrom :: forall x. AttachObject -> Rep AttachObject x
Prelude.Generic)

-- |
-- Create a value of 'AttachObject' 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:
--
-- 'directoryArn', 'attachObject_directoryArn' - Amazon Resource Name (ARN) that is associated with the Directory where
-- both objects reside. For more information, see arns.
--
-- 'parentReference', 'attachObject_parentReference' - The parent object reference.
--
-- 'childReference', 'attachObject_childReference' - The child object reference to be attached to the object.
--
-- 'linkName', 'attachObject_linkName' - The link name with which the child object is attached to the parent.
newAttachObject ::
  -- | 'directoryArn'
  Prelude.Text ->
  -- | 'parentReference'
  ObjectReference ->
  -- | 'childReference'
  ObjectReference ->
  -- | 'linkName'
  Prelude.Text ->
  AttachObject
newAttachObject :: Text -> ObjectReference -> ObjectReference -> Text -> AttachObject
newAttachObject
  Text
pDirectoryArn_
  ObjectReference
pParentReference_
  ObjectReference
pChildReference_
  Text
pLinkName_ =
    AttachObject' :: Text -> ObjectReference -> ObjectReference -> Text -> AttachObject
AttachObject'
      { $sel:directoryArn:AttachObject' :: Text
directoryArn = Text
pDirectoryArn_,
        $sel:parentReference:AttachObject' :: ObjectReference
parentReference = ObjectReference
pParentReference_,
        $sel:childReference:AttachObject' :: ObjectReference
childReference = ObjectReference
pChildReference_,
        $sel:linkName:AttachObject' :: Text
linkName = Text
pLinkName_
      }

-- | Amazon Resource Name (ARN) that is associated with the Directory where
-- both objects reside. For more information, see arns.
attachObject_directoryArn :: Lens.Lens' AttachObject Prelude.Text
attachObject_directoryArn :: (Text -> f Text) -> AttachObject -> f AttachObject
attachObject_directoryArn = (AttachObject -> Text)
-> (AttachObject -> Text -> AttachObject)
-> Lens AttachObject AttachObject Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachObject' {Text
directoryArn :: Text
$sel:directoryArn:AttachObject' :: AttachObject -> Text
directoryArn} -> Text
directoryArn) (\s :: AttachObject
s@AttachObject' {} Text
a -> AttachObject
s {$sel:directoryArn:AttachObject' :: Text
directoryArn = Text
a} :: AttachObject)

-- | The parent object reference.
attachObject_parentReference :: Lens.Lens' AttachObject ObjectReference
attachObject_parentReference :: (ObjectReference -> f ObjectReference)
-> AttachObject -> f AttachObject
attachObject_parentReference = (AttachObject -> ObjectReference)
-> (AttachObject -> ObjectReference -> AttachObject)
-> Lens AttachObject AttachObject ObjectReference ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachObject' {ObjectReference
parentReference :: ObjectReference
$sel:parentReference:AttachObject' :: AttachObject -> ObjectReference
parentReference} -> ObjectReference
parentReference) (\s :: AttachObject
s@AttachObject' {} ObjectReference
a -> AttachObject
s {$sel:parentReference:AttachObject' :: ObjectReference
parentReference = ObjectReference
a} :: AttachObject)

-- | The child object reference to be attached to the object.
attachObject_childReference :: Lens.Lens' AttachObject ObjectReference
attachObject_childReference :: (ObjectReference -> f ObjectReference)
-> AttachObject -> f AttachObject
attachObject_childReference = (AttachObject -> ObjectReference)
-> (AttachObject -> ObjectReference -> AttachObject)
-> Lens AttachObject AttachObject ObjectReference ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachObject' {ObjectReference
childReference :: ObjectReference
$sel:childReference:AttachObject' :: AttachObject -> ObjectReference
childReference} -> ObjectReference
childReference) (\s :: AttachObject
s@AttachObject' {} ObjectReference
a -> AttachObject
s {$sel:childReference:AttachObject' :: ObjectReference
childReference = ObjectReference
a} :: AttachObject)

-- | The link name with which the child object is attached to the parent.
attachObject_linkName :: Lens.Lens' AttachObject Prelude.Text
attachObject_linkName :: (Text -> f Text) -> AttachObject -> f AttachObject
attachObject_linkName = (AttachObject -> Text)
-> (AttachObject -> Text -> AttachObject)
-> Lens AttachObject AttachObject Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachObject' {Text
linkName :: Text
$sel:linkName:AttachObject' :: AttachObject -> Text
linkName} -> Text
linkName) (\s :: AttachObject
s@AttachObject' {} Text
a -> AttachObject
s {$sel:linkName:AttachObject' :: Text
linkName = Text
a} :: AttachObject)

instance Core.AWSRequest AttachObject where
  type AWSResponse AttachObject = AttachObjectResponse
  request :: AttachObject -> Request AttachObject
request = Service -> AttachObject -> Request AttachObject
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AttachObject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AttachObject)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse AttachObject))
-> Logger
-> Service
-> Proxy AttachObject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AttachObject)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> AttachObjectResponse
AttachObjectResponse'
            (Maybe Text -> Int -> AttachObjectResponse)
-> Either String (Maybe Text)
-> Either String (Int -> AttachObjectResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"AttachedObjectIdentifier")
            Either String (Int -> AttachObjectResponse)
-> Either String Int -> Either String AttachObjectResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AttachObject

instance Prelude.NFData AttachObject

instance Core.ToHeaders AttachObject where
  toHeaders :: AttachObject -> ResponseHeaders
toHeaders AttachObject' {Text
ObjectReference
linkName :: Text
childReference :: ObjectReference
parentReference :: ObjectReference
directoryArn :: Text
$sel:linkName:AttachObject' :: AttachObject -> Text
$sel:childReference:AttachObject' :: AttachObject -> ObjectReference
$sel:parentReference:AttachObject' :: AttachObject -> ObjectReference
$sel:directoryArn:AttachObject' :: AttachObject -> Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"x-amz-data-partition" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
directoryArn]

instance Core.ToJSON AttachObject where
  toJSON :: AttachObject -> Value
toJSON AttachObject' {Text
ObjectReference
linkName :: Text
childReference :: ObjectReference
parentReference :: ObjectReference
directoryArn :: Text
$sel:linkName:AttachObject' :: AttachObject -> Text
$sel:childReference:AttachObject' :: AttachObject -> ObjectReference
$sel:parentReference:AttachObject' :: AttachObject -> ObjectReference
$sel:directoryArn:AttachObject' :: AttachObject -> Text
..} =
    [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
"ParentReference" Text -> ObjectReference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ObjectReference
parentReference),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ChildReference" Text -> ObjectReference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ObjectReference
childReference),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"LinkName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
linkName)
          ]
      )

instance Core.ToPath AttachObject where
  toPath :: AttachObject -> ByteString
toPath =
    ByteString -> AttachObject -> ByteString
forall a b. a -> b -> a
Prelude.const
      ByteString
"/amazonclouddirectory/2017-01-11/object/attach"

instance Core.ToQuery AttachObject where
  toQuery :: AttachObject -> QueryString
toQuery = QueryString -> AttachObject -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newAttachObjectResponse' smart constructor.
data AttachObjectResponse = AttachObjectResponse'
  { -- | The attached @ObjectIdentifier@, which is the child @ObjectIdentifier@.
    AttachObjectResponse -> Maybe Text
attachedObjectIdentifier :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    AttachObjectResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AttachObjectResponse -> AttachObjectResponse -> Bool
(AttachObjectResponse -> AttachObjectResponse -> Bool)
-> (AttachObjectResponse -> AttachObjectResponse -> Bool)
-> Eq AttachObjectResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachObjectResponse -> AttachObjectResponse -> Bool
$c/= :: AttachObjectResponse -> AttachObjectResponse -> Bool
== :: AttachObjectResponse -> AttachObjectResponse -> Bool
$c== :: AttachObjectResponse -> AttachObjectResponse -> Bool
Prelude.Eq, ReadPrec [AttachObjectResponse]
ReadPrec AttachObjectResponse
Int -> ReadS AttachObjectResponse
ReadS [AttachObjectResponse]
(Int -> ReadS AttachObjectResponse)
-> ReadS [AttachObjectResponse]
-> ReadPrec AttachObjectResponse
-> ReadPrec [AttachObjectResponse]
-> Read AttachObjectResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachObjectResponse]
$creadListPrec :: ReadPrec [AttachObjectResponse]
readPrec :: ReadPrec AttachObjectResponse
$creadPrec :: ReadPrec AttachObjectResponse
readList :: ReadS [AttachObjectResponse]
$creadList :: ReadS [AttachObjectResponse]
readsPrec :: Int -> ReadS AttachObjectResponse
$creadsPrec :: Int -> ReadS AttachObjectResponse
Prelude.Read, Int -> AttachObjectResponse -> ShowS
[AttachObjectResponse] -> ShowS
AttachObjectResponse -> String
(Int -> AttachObjectResponse -> ShowS)
-> (AttachObjectResponse -> String)
-> ([AttachObjectResponse] -> ShowS)
-> Show AttachObjectResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachObjectResponse] -> ShowS
$cshowList :: [AttachObjectResponse] -> ShowS
show :: AttachObjectResponse -> String
$cshow :: AttachObjectResponse -> String
showsPrec :: Int -> AttachObjectResponse -> ShowS
$cshowsPrec :: Int -> AttachObjectResponse -> ShowS
Prelude.Show, (forall x. AttachObjectResponse -> Rep AttachObjectResponse x)
-> (forall x. Rep AttachObjectResponse x -> AttachObjectResponse)
-> Generic AttachObjectResponse
forall x. Rep AttachObjectResponse x -> AttachObjectResponse
forall x. AttachObjectResponse -> Rep AttachObjectResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachObjectResponse x -> AttachObjectResponse
$cfrom :: forall x. AttachObjectResponse -> Rep AttachObjectResponse x
Prelude.Generic)

-- |
-- Create a value of 'AttachObjectResponse' 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:
--
-- 'attachedObjectIdentifier', 'attachObjectResponse_attachedObjectIdentifier' - The attached @ObjectIdentifier@, which is the child @ObjectIdentifier@.
--
-- 'httpStatus', 'attachObjectResponse_httpStatus' - The response's http status code.
newAttachObjectResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AttachObjectResponse
newAttachObjectResponse :: Int -> AttachObjectResponse
newAttachObjectResponse Int
pHttpStatus_ =
  AttachObjectResponse' :: Maybe Text -> Int -> AttachObjectResponse
AttachObjectResponse'
    { $sel:attachedObjectIdentifier:AttachObjectResponse' :: Maybe Text
attachedObjectIdentifier =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AttachObjectResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The attached @ObjectIdentifier@, which is the child @ObjectIdentifier@.
attachObjectResponse_attachedObjectIdentifier :: Lens.Lens' AttachObjectResponse (Prelude.Maybe Prelude.Text)
attachObjectResponse_attachedObjectIdentifier :: (Maybe Text -> f (Maybe Text))
-> AttachObjectResponse -> f AttachObjectResponse
attachObjectResponse_attachedObjectIdentifier = (AttachObjectResponse -> Maybe Text)
-> (AttachObjectResponse -> Maybe Text -> AttachObjectResponse)
-> Lens
     AttachObjectResponse AttachObjectResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachObjectResponse' {Maybe Text
attachedObjectIdentifier :: Maybe Text
$sel:attachedObjectIdentifier:AttachObjectResponse' :: AttachObjectResponse -> Maybe Text
attachedObjectIdentifier} -> Maybe Text
attachedObjectIdentifier) (\s :: AttachObjectResponse
s@AttachObjectResponse' {} Maybe Text
a -> AttachObjectResponse
s {$sel:attachedObjectIdentifier:AttachObjectResponse' :: Maybe Text
attachedObjectIdentifier = Maybe Text
a} :: AttachObjectResponse)

-- | The response's http status code.
attachObjectResponse_httpStatus :: Lens.Lens' AttachObjectResponse Prelude.Int
attachObjectResponse_httpStatus :: (Int -> f Int) -> AttachObjectResponse -> f AttachObjectResponse
attachObjectResponse_httpStatus = (AttachObjectResponse -> Int)
-> (AttachObjectResponse -> Int -> AttachObjectResponse)
-> Lens AttachObjectResponse AttachObjectResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachObjectResponse' {Int
httpStatus :: Int
$sel:httpStatus:AttachObjectResponse' :: AttachObjectResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: AttachObjectResponse
s@AttachObjectResponse' {} Int
a -> AttachObjectResponse
s {$sel:httpStatus:AttachObjectResponse' :: Int
httpStatus = Int
a} :: AttachObjectResponse)

instance Prelude.NFData AttachObjectResponse