{-# 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-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)
--
-- 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 mitigation.
--
-- 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.Lens as Lens
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
(AssociateHealthCheck -> AssociateHealthCheck -> Bool)
-> (AssociateHealthCheck -> AssociateHealthCheck -> Bool)
-> Eq AssociateHealthCheck
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]
(Int -> ReadS AssociateHealthCheck)
-> ReadS [AssociateHealthCheck]
-> ReadPrec AssociateHealthCheck
-> ReadPrec [AssociateHealthCheck]
-> Read 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
(Int -> AssociateHealthCheck -> ShowS)
-> (AssociateHealthCheck -> String)
-> ([AssociateHealthCheck] -> ShowS)
-> Show AssociateHealthCheck
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. AssociateHealthCheck -> Rep AssociateHealthCheck x)
-> (forall x. Rep AssociateHealthCheck x -> AssociateHealthCheck)
-> Generic AssociateHealthCheck
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' :: Text -> Text -> AssociateHealthCheck
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 :: (Text -> f Text) -> AssociateHealthCheck -> f AssociateHealthCheck
associateHealthCheck_protectionId = (AssociateHealthCheck -> Text)
-> (AssociateHealthCheck -> Text -> AssociateHealthCheck)
-> Lens AssociateHealthCheck AssociateHealthCheck Text Text
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 :: (Text -> f Text) -> AssociateHealthCheck -> f AssociateHealthCheck
associateHealthCheck_healthCheckArn = (AssociateHealthCheck -> Text)
-> (AssociateHealthCheck -> Text -> AssociateHealthCheck)
-> Lens AssociateHealthCheck AssociateHealthCheck Text Text
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 :: AssociateHealthCheck -> Request AssociateHealthCheck
request = Service -> AssociateHealthCheck -> Request AssociateHealthCheck
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AssociateHealthCheck
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateHealthCheck)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse AssociateHealthCheck))
-> Logger
-> Service
-> Proxy AssociateHealthCheck
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateHealthCheck)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> AssociateHealthCheckResponse
AssociateHealthCheckResponse'
            (Int -> AssociateHealthCheckResponse)
-> Either String Int -> Either String AssociateHealthCheckResponse
forall (f :: * -> *) a b. Functor 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 AssociateHealthCheck

instance Prelude.NFData AssociateHealthCheck

instance Core.ToHeaders AssociateHealthCheck where
  toHeaders :: AssociateHealthCheck -> ResponseHeaders
toHeaders =
    ResponseHeaders -> AssociateHealthCheck -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSShield_20160616.AssociateHealthCheck" ::
                          Prelude.ByteString
                      ),
            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 AssociateHealthCheck where
  toJSON :: AssociateHealthCheck -> Value
toJSON AssociateHealthCheck' {Text
healthCheckArn :: Text
protectionId :: Text
$sel:healthCheckArn:AssociateHealthCheck' :: AssociateHealthCheck -> Text
$sel:protectionId:AssociateHealthCheck' :: AssociateHealthCheck -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ProtectionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
protectionId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"HealthCheckArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
healthCheckArn)
          ]
      )

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

instance Core.ToQuery AssociateHealthCheck where
  toQuery :: AssociateHealthCheck -> QueryString
toQuery = QueryString -> AssociateHealthCheck -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(AssociateHealthCheckResponse
 -> AssociateHealthCheckResponse -> Bool)
-> (AssociateHealthCheckResponse
    -> AssociateHealthCheckResponse -> Bool)
-> Eq AssociateHealthCheckResponse
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]
(Int -> ReadS AssociateHealthCheckResponse)
-> ReadS [AssociateHealthCheckResponse]
-> ReadPrec AssociateHealthCheckResponse
-> ReadPrec [AssociateHealthCheckResponse]
-> Read 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
(Int -> AssociateHealthCheckResponse -> ShowS)
-> (AssociateHealthCheckResponse -> String)
-> ([AssociateHealthCheckResponse] -> ShowS)
-> Show AssociateHealthCheckResponse
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.
 AssociateHealthCheckResponse -> Rep AssociateHealthCheckResponse x)
-> (forall x.
    Rep AssociateHealthCheckResponse x -> AssociateHealthCheckResponse)
-> Generic AssociateHealthCheckResponse
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' :: Int -> AssociateHealthCheckResponse
AssociateHealthCheckResponse'
    { $sel:httpStatus:AssociateHealthCheckResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
associateHealthCheckResponse_httpStatus :: Lens.Lens' AssociateHealthCheckResponse Prelude.Int
associateHealthCheckResponse_httpStatus :: (Int -> f Int)
-> AssociateHealthCheckResponse -> f AssociateHealthCheckResponse
associateHealthCheckResponse_httpStatus = (AssociateHealthCheckResponse -> Int)
-> (AssociateHealthCheckResponse
    -> Int -> AssociateHealthCheckResponse)
-> Lens
     AssociateHealthCheckResponse AssociateHealthCheckResponse Int Int
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