{-# 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.Synthetics.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 canary with a group. Using groups can help you with
-- managing and automating your canaries, and you can also view aggregated
-- run results and statistics for all canaries in a group.
--
-- You must run this operation in the Region where the canary exists.
module Amazonka.Synthetics.AssociateResource
  ( -- * Creating a Request
    AssociateResource (..),
    newAssociateResource,

    -- * Request Lenses
    associateResource_groupIdentifier,
    associateResource_resourceArn,

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

    -- * Response Lenses
    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.Synthetics.Types

-- | /See:/ 'newAssociateResource' smart constructor.
data AssociateResource = AssociateResource'
  { -- | Specifies the group. You can specify the group name, the ARN, or the
    -- group ID as the @GroupIdentifier@.
    AssociateResource -> Text
groupIdentifier :: Prelude.Text,
    -- | The ARN of the canary that you want to associate with the specified
    -- group.
    AssociateResource -> Text
resourceArn :: 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:
--
-- 'groupIdentifier', 'associateResource_groupIdentifier' - Specifies the group. You can specify the group name, the ARN, or the
-- group ID as the @GroupIdentifier@.
--
-- 'resourceArn', 'associateResource_resourceArn' - The ARN of the canary that you want to associate with the specified
-- group.
newAssociateResource ::
  -- | 'groupIdentifier'
  Prelude.Text ->
  -- | 'resourceArn'
  Prelude.Text ->
  AssociateResource
newAssociateResource :: Text -> Text -> AssociateResource
newAssociateResource Text
pGroupIdentifier_ Text
pResourceArn_ =
  AssociateResource'
    { $sel:groupIdentifier:AssociateResource' :: Text
groupIdentifier =
        Text
pGroupIdentifier_,
      $sel:resourceArn:AssociateResource' :: Text
resourceArn = Text
pResourceArn_
    }

-- | Specifies the group. You can specify the group name, the ARN, or the
-- group ID as the @GroupIdentifier@.
associateResource_groupIdentifier :: Lens.Lens' AssociateResource Prelude.Text
associateResource_groupIdentifier :: Lens' AssociateResource Text
associateResource_groupIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResource' {Text
groupIdentifier :: Text
$sel:groupIdentifier:AssociateResource' :: AssociateResource -> Text
groupIdentifier} -> Text
groupIdentifier) (\s :: AssociateResource
s@AssociateResource' {} Text
a -> AssociateResource
s {$sel:groupIdentifier:AssociateResource' :: Text
groupIdentifier = Text
a} :: AssociateResource)

-- | The ARN of the canary that you want to associate with the specified
-- group.
associateResource_resourceArn :: Lens.Lens' AssociateResource Prelude.Text
associateResource_resourceArn :: Lens' AssociateResource Text
associateResource_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResource' {Text
resourceArn :: Text
$sel:resourceArn:AssociateResource' :: AssociateResource -> Text
resourceArn} -> Text
resourceArn) (\s :: AssociateResource
s@AssociateResource' {} Text
a -> AssociateResource
s {$sel:resourceArn:AssociateResource' :: Text
resourceArn = 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.patchJSON (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 -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> AssociateResourceResponse
AssociateResourceResponse'
            forall (f :: * -> *) a b. Functor 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
resourceArn :: Text
groupIdentifier :: Text
$sel:resourceArn:AssociateResource' :: AssociateResource -> Text
$sel:groupIdentifier:AssociateResource' :: AssociateResource -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
groupIdentifier
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resourceArn

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

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 AssociateResource' {Text
resourceArn :: Text
groupIdentifier :: Text
$sel:resourceArn:AssociateResource' :: AssociateResource -> Text
$sel:groupIdentifier:AssociateResource' :: AssociateResource -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"ResourceArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
resourceArn)]
      )

instance Data.ToPath AssociateResource where
  toPath :: AssociateResource -> ByteString
toPath AssociateResource' {Text
resourceArn :: Text
groupIdentifier :: Text
$sel:resourceArn:AssociateResource' :: AssociateResource -> Text
$sel:groupIdentifier:AssociateResource' :: AssociateResource -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/group/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
groupIdentifier, ByteString
"/associate"]

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 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:
--
-- 'httpStatus', 'associateResourceResponse_httpStatus' - The response's http status code.
newAssociateResourceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociateResourceResponse
newAssociateResourceResponse :: Int -> AssociateResourceResponse
newAssociateResourceResponse Int
pHttpStatus_ =
  AssociateResourceResponse'
    { $sel:httpStatus:AssociateResourceResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | 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
httpStatus :: Int
$sel:httpStatus:AssociateResourceResponse' :: AssociateResourceResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus