{-# 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-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)
--
-- 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.Lens as Lens
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
(AssociateResource -> AssociateResource -> Bool)
-> (AssociateResource -> AssociateResource -> Bool)
-> Eq AssociateResource
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]
(Int -> ReadS AssociateResource)
-> ReadS [AssociateResource]
-> ReadPrec AssociateResource
-> ReadPrec [AssociateResource]
-> Read 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
(Int -> AssociateResource -> ShowS)
-> (AssociateResource -> String)
-> ([AssociateResource] -> ShowS)
-> Show AssociateResource
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. AssociateResource -> Rep AssociateResource x)
-> (forall x. Rep AssociateResource x -> AssociateResource)
-> Generic AssociateResource
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' :: Text -> ResourceType -> Text -> AssociateResource
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 :: (Text -> f Text) -> AssociateResource -> f AssociateResource
associateResource_application = (AssociateResource -> Text)
-> (AssociateResource -> Text -> AssociateResource)
-> Lens AssociateResource AssociateResource Text Text
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 :: (ResourceType -> f ResourceType)
-> AssociateResource -> f AssociateResource
associateResource_resourceType = (AssociateResource -> ResourceType)
-> (AssociateResource -> ResourceType -> AssociateResource)
-> Lens
     AssociateResource AssociateResource ResourceType 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 :: (Text -> f Text) -> AssociateResource -> f AssociateResource
associateResource_resource = (AssociateResource -> Text)
-> (AssociateResource -> Text -> AssociateResource)
-> Lens AssociateResource AssociateResource Text Text
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 :: AssociateResource -> Request AssociateResource
request = Service -> AssociateResource -> Request AssociateResource
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AssociateResource
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateResource)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse AssociateResource))
-> Logger
-> Service
-> Proxy AssociateResource
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateResource)))
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 -> Maybe Text -> Int -> AssociateResourceResponse
AssociateResourceResponse'
            (Maybe Text -> Maybe Text -> Int -> AssociateResourceResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> AssociateResourceResponse)
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
"applicationArn")
            Either String (Maybe Text -> Int -> AssociateResourceResponse)
-> Either String (Maybe Text)
-> Either String (Int -> AssociateResourceResponse)
forall (f :: * -> *) a b. Applicative f => 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
"resourceArn")
            Either String (Int -> AssociateResourceResponse)
-> Either String Int -> Either String AssociateResourceResponse
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 AssociateResource

instance Prelude.NFData AssociateResource

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

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

instance Core.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
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/applications/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
application,
        ByteString
"/resources/",
        ResourceType -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS ResourceType
resourceType,
        ByteString
"/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
resource
      ]

instance Core.ToQuery AssociateResource where
  toQuery :: AssociateResource -> QueryString
toQuery = QueryString -> AssociateResource -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(AssociateResourceResponse -> AssociateResourceResponse -> Bool)
-> (AssociateResourceResponse -> AssociateResourceResponse -> Bool)
-> Eq AssociateResourceResponse
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]
(Int -> ReadS AssociateResourceResponse)
-> ReadS [AssociateResourceResponse]
-> ReadPrec AssociateResourceResponse
-> ReadPrec [AssociateResourceResponse]
-> Read 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
(Int -> AssociateResourceResponse -> ShowS)
-> (AssociateResourceResponse -> String)
-> ([AssociateResourceResponse] -> ShowS)
-> Show AssociateResourceResponse
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.
 AssociateResourceResponse -> Rep AssociateResourceResponse x)
-> (forall x.
    Rep AssociateResourceResponse x -> AssociateResourceResponse)
-> Generic AssociateResourceResponse
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' :: Maybe Text -> Maybe Text -> Int -> AssociateResourceResponse
AssociateResourceResponse'
    { $sel:applicationArn:AssociateResourceResponse' :: Maybe Text
applicationArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceArn:AssociateResourceResponse' :: Maybe Text
resourceArn = Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> AssociateResourceResponse -> f AssociateResourceResponse
associateResourceResponse_applicationArn = (AssociateResourceResponse -> Maybe Text)
-> (AssociateResourceResponse
    -> Maybe Text -> AssociateResourceResponse)
-> Lens
     AssociateResourceResponse
     AssociateResourceResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text))
-> AssociateResourceResponse -> f AssociateResourceResponse
associateResourceResponse_resourceArn = (AssociateResourceResponse -> Maybe Text)
-> (AssociateResourceResponse
    -> Maybe Text -> AssociateResourceResponse)
-> Lens
     AssociateResourceResponse
     AssociateResourceResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Int -> f Int)
-> AssociateResourceResponse -> f AssociateResourceResponse
associateResourceResponse_httpStatus = (AssociateResourceResponse -> Int)
-> (AssociateResourceResponse -> Int -> AssociateResourceResponse)
-> Lens AssociateResourceResponse AssociateResourceResponse Int Int
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