{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
      { $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 :: Lens' AttachObject Text
attachObject_directoryArn = 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 :: Lens' AttachObject ObjectReference
attachObject_parentReference = 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 :: Lens' AttachObject ObjectReference
attachObject_childReference = 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 :: Lens' AttachObject Text
attachObject_linkName = 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 :: (Service -> Service) -> AttachObject -> Request AttachObject
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AttachObject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AttachObject)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> AttachObjectResponse
AttachObjectResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"AttachedObjectIdentifier")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AttachObject where
  hashWithSalt :: Int -> AttachObject -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
directoryArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ObjectReference
parentReference
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ObjectReference
childReference
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
linkName

instance Prelude.NFData AttachObject where
  rnf :: AttachObject -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
directoryArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ObjectReference
parentReference
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ObjectReference
childReference
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
linkName

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"x-amz-data-partition" forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# Text
directoryArn]

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"ParentReference" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ObjectReference
parentReference),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ChildReference" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ObjectReference
childReference),
            forall a. a -> Maybe a
Prelude.Just (Key
"LinkName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
linkName)
          ]
      )

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

instance Data.ToQuery AttachObject where
  toQuery :: AttachObject -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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. 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'
    { $sel:attachedObjectIdentifier:AttachObjectResponse' :: Maybe Text
attachedObjectIdentifier =
        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 :: Lens' AttachObjectResponse (Maybe Text)
attachObjectResponse_attachedObjectIdentifier = 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 :: Lens' AttachObjectResponse Int
attachObjectResponse_httpStatus = 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 where
  rnf :: AttachObjectResponse -> ()
rnf AttachObjectResponse' {Int
Maybe Text
httpStatus :: Int
attachedObjectIdentifier :: Maybe Text
$sel:httpStatus:AttachObjectResponse' :: AttachObjectResponse -> Int
$sel:attachedObjectIdentifier:AttachObjectResponse' :: AttachObjectResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
attachedObjectIdentifier
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus