{-# 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.Shield.AssociateHealthCheck
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Adds health-based detection to the Shield Advanced protection for a
-- resource. Shield Advanced health-based detection uses the health of your
-- Amazon Web Services resource to improve responsiveness and accuracy in
-- attack detection and response.
--
-- You define the health check in Route 53 and then associate it with your
-- Shield Advanced protection. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/ddos-overview.html#ddos-advanced-health-check-option Shield Advanced Health-Based Detection>
-- in the /WAF Developer Guide/.
module Amazonka.Shield.AssociateHealthCheck
  ( -- * Creating a Request
    AssociateHealthCheck (..),
    newAssociateHealthCheck,

    -- * Request Lenses
    associateHealthCheck_protectionId,
    associateHealthCheck_healthCheckArn,

    -- * Destructuring the Response
    AssociateHealthCheckResponse (..),
    newAssociateHealthCheckResponse,

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

-- | /See:/ 'newAssociateHealthCheck' smart constructor.
data AssociateHealthCheck = AssociateHealthCheck'
  { -- | The unique identifier (ID) for the Protection object to add the health
    -- check association to.
    AssociateHealthCheck -> Text
protectionId :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the health check to associate with the
    -- protection.
    AssociateHealthCheck -> Text
healthCheckArn :: Prelude.Text
  }
  deriving (AssociateHealthCheck -> AssociateHealthCheck -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateHealthCheck -> AssociateHealthCheck -> Bool
$c/= :: AssociateHealthCheck -> AssociateHealthCheck -> Bool
== :: AssociateHealthCheck -> AssociateHealthCheck -> Bool
$c== :: AssociateHealthCheck -> AssociateHealthCheck -> Bool
Prelude.Eq, ReadPrec [AssociateHealthCheck]
ReadPrec AssociateHealthCheck
Int -> ReadS AssociateHealthCheck
ReadS [AssociateHealthCheck]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateHealthCheck]
$creadListPrec :: ReadPrec [AssociateHealthCheck]
readPrec :: ReadPrec AssociateHealthCheck
$creadPrec :: ReadPrec AssociateHealthCheck
readList :: ReadS [AssociateHealthCheck]
$creadList :: ReadS [AssociateHealthCheck]
readsPrec :: Int -> ReadS AssociateHealthCheck
$creadsPrec :: Int -> ReadS AssociateHealthCheck
Prelude.Read, Int -> AssociateHealthCheck -> ShowS
[AssociateHealthCheck] -> ShowS
AssociateHealthCheck -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateHealthCheck] -> ShowS
$cshowList :: [AssociateHealthCheck] -> ShowS
show :: AssociateHealthCheck -> String
$cshow :: AssociateHealthCheck -> String
showsPrec :: Int -> AssociateHealthCheck -> ShowS
$cshowsPrec :: Int -> AssociateHealthCheck -> ShowS
Prelude.Show, forall x. Rep AssociateHealthCheck x -> AssociateHealthCheck
forall x. AssociateHealthCheck -> Rep AssociateHealthCheck x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateHealthCheck x -> AssociateHealthCheck
$cfrom :: forall x. AssociateHealthCheck -> Rep AssociateHealthCheck x
Prelude.Generic)

-- |
-- Create a value of 'AssociateHealthCheck' 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:
--
-- 'protectionId', 'associateHealthCheck_protectionId' - The unique identifier (ID) for the Protection object to add the health
-- check association to.
--
-- 'healthCheckArn', 'associateHealthCheck_healthCheckArn' - The Amazon Resource Name (ARN) of the health check to associate with the
-- protection.
newAssociateHealthCheck ::
  -- | 'protectionId'
  Prelude.Text ->
  -- | 'healthCheckArn'
  Prelude.Text ->
  AssociateHealthCheck
newAssociateHealthCheck :: Text -> Text -> AssociateHealthCheck
newAssociateHealthCheck
  Text
pProtectionId_
  Text
pHealthCheckArn_ =
    AssociateHealthCheck'
      { $sel:protectionId:AssociateHealthCheck' :: Text
protectionId =
          Text
pProtectionId_,
        $sel:healthCheckArn:AssociateHealthCheck' :: Text
healthCheckArn = Text
pHealthCheckArn_
      }

-- | The unique identifier (ID) for the Protection object to add the health
-- check association to.
associateHealthCheck_protectionId :: Lens.Lens' AssociateHealthCheck Prelude.Text
associateHealthCheck_protectionId :: Lens' AssociateHealthCheck Text
associateHealthCheck_protectionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateHealthCheck' {Text
protectionId :: Text
$sel:protectionId:AssociateHealthCheck' :: AssociateHealthCheck -> Text
protectionId} -> Text
protectionId) (\s :: AssociateHealthCheck
s@AssociateHealthCheck' {} Text
a -> AssociateHealthCheck
s {$sel:protectionId:AssociateHealthCheck' :: Text
protectionId = Text
a} :: AssociateHealthCheck)

-- | The Amazon Resource Name (ARN) of the health check to associate with the
-- protection.
associateHealthCheck_healthCheckArn :: Lens.Lens' AssociateHealthCheck Prelude.Text
associateHealthCheck_healthCheckArn :: Lens' AssociateHealthCheck Text
associateHealthCheck_healthCheckArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateHealthCheck' {Text
healthCheckArn :: Text
$sel:healthCheckArn:AssociateHealthCheck' :: AssociateHealthCheck -> Text
healthCheckArn} -> Text
healthCheckArn) (\s :: AssociateHealthCheck
s@AssociateHealthCheck' {} Text
a -> AssociateHealthCheck
s {$sel:healthCheckArn:AssociateHealthCheck' :: Text
healthCheckArn = Text
a} :: AssociateHealthCheck)

instance Core.AWSRequest AssociateHealthCheck where
  type
    AWSResponse AssociateHealthCheck =
      AssociateHealthCheckResponse
  request :: (Service -> Service)
-> AssociateHealthCheck -> Request AssociateHealthCheck
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AssociateHealthCheck
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateHealthCheck)))
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 -> AssociateHealthCheckResponse
AssociateHealthCheckResponse'
            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 AssociateHealthCheck where
  hashWithSalt :: Int -> AssociateHealthCheck -> Int
hashWithSalt Int
_salt AssociateHealthCheck' {Text
healthCheckArn :: Text
protectionId :: Text
$sel:healthCheckArn:AssociateHealthCheck' :: AssociateHealthCheck -> Text
$sel:protectionId:AssociateHealthCheck' :: AssociateHealthCheck -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
protectionId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
healthCheckArn

instance Prelude.NFData AssociateHealthCheck where
  rnf :: AssociateHealthCheck -> ()
rnf AssociateHealthCheck' {Text
healthCheckArn :: Text
protectionId :: Text
$sel:healthCheckArn:AssociateHealthCheck' :: AssociateHealthCheck -> Text
$sel:protectionId:AssociateHealthCheck' :: AssociateHealthCheck -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
protectionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
healthCheckArn

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

instance Data.ToJSON AssociateHealthCheck where
  toJSON :: AssociateHealthCheck -> Value
toJSON AssociateHealthCheck' {Text
healthCheckArn :: Text
protectionId :: Text
$sel:healthCheckArn:AssociateHealthCheck' :: AssociateHealthCheck -> Text
$sel:protectionId:AssociateHealthCheck' :: AssociateHealthCheck -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"ProtectionId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
protectionId),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"HealthCheckArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
healthCheckArn)
          ]
      )

instance Data.ToPath AssociateHealthCheck where
  toPath :: AssociateHealthCheck -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'AssociateHealthCheckResponse' 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', 'associateHealthCheckResponse_httpStatus' - The response's http status code.
newAssociateHealthCheckResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociateHealthCheckResponse
newAssociateHealthCheckResponse :: Int -> AssociateHealthCheckResponse
newAssociateHealthCheckResponse Int
pHttpStatus_ =
  AssociateHealthCheckResponse'
    { $sel:httpStatus:AssociateHealthCheckResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData AssociateHealthCheckResponse where
  rnf :: AssociateHealthCheckResponse -> ()
rnf AssociateHealthCheckResponse' {Int
httpStatus :: Int
$sel:httpStatus:AssociateHealthCheckResponse' :: AssociateHealthCheckResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus