{-# 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.ServiceCatalogAppRegistry.AssociateResource
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Associates a resource with an application. Both the resource and the
-- application can be specified either by ID or name.
module Amazonka.ServiceCatalogAppRegistry.AssociateResource
  ( -- * Creating a Request
    AssociateResource (..),
    newAssociateResource,

    -- * Request Lenses
    associateResource_application,
    associateResource_resourceType,
    associateResource_resource,

    -- * Destructuring the Response
    AssociateResourceResponse (..),
    newAssociateResourceResponse,

    -- * Response Lenses
    associateResourceResponse_applicationArn,
    associateResourceResponse_resourceArn,
    associateResourceResponse_httpStatus,
  )
where

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
import Amazonka.ServiceCatalogAppRegistry.Types

-- | /See:/ 'newAssociateResource' smart constructor.
data AssociateResource = AssociateResource'
  { -- | The name or ID of the application.
    AssociateResource -> Text
application :: Prelude.Text,
    -- | The type of resource of which the application will be associated.
    AssociateResource -> ResourceType
resourceType :: ResourceType,
    -- | The name or ID of the resource of which the application will be
    -- associated.
    AssociateResource -> Text
resource :: Prelude.Text
  }
  deriving (AssociateResource -> AssociateResource -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateResource -> AssociateResource -> Bool
$c/= :: AssociateResource -> AssociateResource -> Bool
== :: AssociateResource -> AssociateResource -> Bool
$c== :: AssociateResource -> AssociateResource -> Bool
Prelude.Eq, ReadPrec [AssociateResource]
ReadPrec AssociateResource
Int -> ReadS AssociateResource
ReadS [AssociateResource]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateResource]
$creadListPrec :: ReadPrec [AssociateResource]
readPrec :: ReadPrec AssociateResource
$creadPrec :: ReadPrec AssociateResource
readList :: ReadS [AssociateResource]
$creadList :: ReadS [AssociateResource]
readsPrec :: Int -> ReadS AssociateResource
$creadsPrec :: Int -> ReadS AssociateResource
Prelude.Read, Int -> AssociateResource -> ShowS
[AssociateResource] -> ShowS
AssociateResource -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateResource] -> ShowS
$cshowList :: [AssociateResource] -> ShowS
show :: AssociateResource -> String
$cshow :: AssociateResource -> String
showsPrec :: Int -> AssociateResource -> ShowS
$cshowsPrec :: Int -> AssociateResource -> ShowS
Prelude.Show, forall x. Rep AssociateResource x -> AssociateResource
forall x. AssociateResource -> Rep AssociateResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateResource x -> AssociateResource
$cfrom :: forall x. AssociateResource -> Rep AssociateResource x
Prelude.Generic)

-- |
-- Create a value of 'AssociateResource' 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:
--
-- 'application', 'associateResource_application' - The name or ID of the application.
--
-- 'resourceType', 'associateResource_resourceType' - The type of resource of which the application will be associated.
--
-- 'resource', 'associateResource_resource' - The name or ID of the resource of which the application will be
-- associated.
newAssociateResource ::
  -- | 'application'
  Prelude.Text ->
  -- | 'resourceType'
  ResourceType ->
  -- | 'resource'
  Prelude.Text ->
  AssociateResource
newAssociateResource :: Text -> ResourceType -> Text -> AssociateResource
newAssociateResource
  Text
pApplication_
  ResourceType
pResourceType_
  Text
pResource_ =
    AssociateResource'
      { $sel:application:AssociateResource' :: Text
application = Text
pApplication_,
        $sel:resourceType:AssociateResource' :: ResourceType
resourceType = ResourceType
pResourceType_,
        $sel:resource:AssociateResource' :: Text
resource = Text
pResource_
      }

-- | The name or ID of the application.
associateResource_application :: Lens.Lens' AssociateResource Prelude.Text
associateResource_application :: Lens' AssociateResource Text
associateResource_application = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResource' {Text
application :: Text
$sel:application:AssociateResource' :: AssociateResource -> Text
application} -> Text
application) (\s :: AssociateResource
s@AssociateResource' {} Text
a -> AssociateResource
s {$sel:application:AssociateResource' :: Text
application = Text
a} :: AssociateResource)

-- | The type of resource of which the application will be associated.
associateResource_resourceType :: Lens.Lens' AssociateResource ResourceType
associateResource_resourceType :: Lens' AssociateResource ResourceType
associateResource_resourceType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResource' {ResourceType
resourceType :: ResourceType
$sel:resourceType:AssociateResource' :: AssociateResource -> ResourceType
resourceType} -> ResourceType
resourceType) (\s :: AssociateResource
s@AssociateResource' {} ResourceType
a -> AssociateResource
s {$sel:resourceType:AssociateResource' :: ResourceType
resourceType = ResourceType
a} :: AssociateResource)

-- | The name or ID of the resource of which the application will be
-- associated.
associateResource_resource :: Lens.Lens' AssociateResource Prelude.Text
associateResource_resource :: Lens' AssociateResource Text
associateResource_resource = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResource' {Text
resource :: Text
$sel:resource:AssociateResource' :: AssociateResource -> Text
resource} -> Text
resource) (\s :: AssociateResource
s@AssociateResource' {} Text
a -> AssociateResource
s {$sel:resource:AssociateResource' :: Text
resource = Text
a} :: AssociateResource)

instance Core.AWSRequest AssociateResource where
  type
    AWSResponse AssociateResource =
      AssociateResourceResponse
  request :: (Service -> Service)
-> AssociateResource -> Request AssociateResource
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 AssociateResource
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateResource)))
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 -> Maybe Text -> Int -> AssociateResourceResponse
AssociateResourceResponse'
            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
"applicationArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"resourceArn")
            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 AssociateResource where
  hashWithSalt :: Int -> AssociateResource -> Int
hashWithSalt Int
_salt AssociateResource' {Text
ResourceType
resource :: Text
resourceType :: ResourceType
application :: Text
$sel:resource:AssociateResource' :: AssociateResource -> Text
$sel:resourceType:AssociateResource' :: AssociateResource -> ResourceType
$sel:application:AssociateResource' :: AssociateResource -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
application
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ResourceType
resourceType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resource

instance Prelude.NFData AssociateResource where
  rnf :: AssociateResource -> ()
rnf AssociateResource' {Text
ResourceType
resource :: Text
resourceType :: ResourceType
application :: Text
$sel:resource:AssociateResource' :: AssociateResource -> Text
$sel:resourceType:AssociateResource' :: AssociateResource -> ResourceType
$sel:application:AssociateResource' :: AssociateResource -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
application
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ResourceType
resourceType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
resource

instance Data.ToHeaders AssociateResource where
  toHeaders :: AssociateResource -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON AssociateResource where
  toJSON :: AssociateResource -> Value
toJSON = forall a b. a -> b -> a
Prelude.const (Object -> Value
Data.Object forall a. Monoid a => a
Prelude.mempty)

instance Data.ToPath AssociateResource where
  toPath :: AssociateResource -> ByteString
toPath AssociateResource' {Text
ResourceType
resource :: Text
resourceType :: ResourceType
application :: Text
$sel:resource:AssociateResource' :: AssociateResource -> Text
$sel:resourceType:AssociateResource' :: AssociateResource -> ResourceType
$sel:application:AssociateResource' :: AssociateResource -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/applications/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
application,
        ByteString
"/resources/",
        forall a. ToByteString a => a -> ByteString
Data.toBS ResourceType
resourceType,
        ByteString
"/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
resource
      ]

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

-- | /See:/ 'newAssociateResourceResponse' smart constructor.
data AssociateResourceResponse = AssociateResourceResponse'
  { -- | The Amazon resource name (ARN) of the application that was augmented
    -- with attributes.
    AssociateResourceResponse -> Maybe Text
applicationArn :: Prelude.Maybe Prelude.Text,
    -- | The Amazon resource name (ARN) that specifies the resource.
    AssociateResourceResponse -> Maybe Text
resourceArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    AssociateResourceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AssociateResourceResponse -> AssociateResourceResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateResourceResponse -> AssociateResourceResponse -> Bool
$c/= :: AssociateResourceResponse -> AssociateResourceResponse -> Bool
== :: AssociateResourceResponse -> AssociateResourceResponse -> Bool
$c== :: AssociateResourceResponse -> AssociateResourceResponse -> Bool
Prelude.Eq, ReadPrec [AssociateResourceResponse]
ReadPrec AssociateResourceResponse
Int -> ReadS AssociateResourceResponse
ReadS [AssociateResourceResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateResourceResponse]
$creadListPrec :: ReadPrec [AssociateResourceResponse]
readPrec :: ReadPrec AssociateResourceResponse
$creadPrec :: ReadPrec AssociateResourceResponse
readList :: ReadS [AssociateResourceResponse]
$creadList :: ReadS [AssociateResourceResponse]
readsPrec :: Int -> ReadS AssociateResourceResponse
$creadsPrec :: Int -> ReadS AssociateResourceResponse
Prelude.Read, Int -> AssociateResourceResponse -> ShowS
[AssociateResourceResponse] -> ShowS
AssociateResourceResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateResourceResponse] -> ShowS
$cshowList :: [AssociateResourceResponse] -> ShowS
show :: AssociateResourceResponse -> String
$cshow :: AssociateResourceResponse -> String
showsPrec :: Int -> AssociateResourceResponse -> ShowS
$cshowsPrec :: Int -> AssociateResourceResponse -> ShowS
Prelude.Show, forall x.
Rep AssociateResourceResponse x -> AssociateResourceResponse
forall x.
AssociateResourceResponse -> Rep AssociateResourceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateResourceResponse x -> AssociateResourceResponse
$cfrom :: forall x.
AssociateResourceResponse -> Rep AssociateResourceResponse x
Prelude.Generic)

-- |
-- Create a value of 'AssociateResourceResponse' 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:
--
-- 'applicationArn', 'associateResourceResponse_applicationArn' - The Amazon resource name (ARN) of the application that was augmented
-- with attributes.
--
-- 'resourceArn', 'associateResourceResponse_resourceArn' - The Amazon resource name (ARN) that specifies the resource.
--
-- 'httpStatus', 'associateResourceResponse_httpStatus' - The response's http status code.
newAssociateResourceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociateResourceResponse
newAssociateResourceResponse :: Int -> AssociateResourceResponse
newAssociateResourceResponse Int
pHttpStatus_ =
  AssociateResourceResponse'
    { $sel:applicationArn:AssociateResourceResponse' :: Maybe Text
applicationArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:resourceArn:AssociateResourceResponse' :: Maybe Text
resourceArn = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AssociateResourceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon resource name (ARN) of the application that was augmented
-- with attributes.
associateResourceResponse_applicationArn :: Lens.Lens' AssociateResourceResponse (Prelude.Maybe Prelude.Text)
associateResourceResponse_applicationArn :: Lens' AssociateResourceResponse (Maybe Text)
associateResourceResponse_applicationArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResourceResponse' {Maybe Text
applicationArn :: Maybe Text
$sel:applicationArn:AssociateResourceResponse' :: AssociateResourceResponse -> Maybe Text
applicationArn} -> Maybe Text
applicationArn) (\s :: AssociateResourceResponse
s@AssociateResourceResponse' {} Maybe Text
a -> AssociateResourceResponse
s {$sel:applicationArn:AssociateResourceResponse' :: Maybe Text
applicationArn = Maybe Text
a} :: AssociateResourceResponse)

-- | The Amazon resource name (ARN) that specifies the resource.
associateResourceResponse_resourceArn :: Lens.Lens' AssociateResourceResponse (Prelude.Maybe Prelude.Text)
associateResourceResponse_resourceArn :: Lens' AssociateResourceResponse (Maybe Text)
associateResourceResponse_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResourceResponse' {Maybe Text
resourceArn :: Maybe Text
$sel:resourceArn:AssociateResourceResponse' :: AssociateResourceResponse -> Maybe Text
resourceArn} -> Maybe Text
resourceArn) (\s :: AssociateResourceResponse
s@AssociateResourceResponse' {} Maybe Text
a -> AssociateResourceResponse
s {$sel:resourceArn:AssociateResourceResponse' :: Maybe Text
resourceArn = Maybe Text
a} :: AssociateResourceResponse)

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

instance Prelude.NFData AssociateResourceResponse where
  rnf :: AssociateResourceResponse -> ()
rnf AssociateResourceResponse' {Int
Maybe Text
httpStatus :: Int
resourceArn :: Maybe Text
applicationArn :: Maybe Text
$sel:httpStatus:AssociateResourceResponse' :: AssociateResourceResponse -> Int
$sel:resourceArn:AssociateResourceResponse' :: AssociateResourceResponse -> Maybe Text
$sel:applicationArn:AssociateResourceResponse' :: AssociateResourceResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
applicationArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
resourceArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus