{-# 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.ELBV2.RegisterTargets
-- 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)
--
-- Registers the specified targets with the specified target group.
--
-- If the target is an EC2 instance, it must be in the @running@ state when
-- you register it.
--
-- By default, the load balancer routes requests to registered targets
-- using the protocol and port for the target group. Alternatively, you can
-- override the port for a target when you register it. You can register
-- each EC2 instance or IP address with the same target group multiple
-- times using different ports.
--
-- With a Network Load Balancer, you cannot register instances by instance
-- ID if they have the following instance types: C1, CC1, CC2, CG1, CG2,
-- CR1, CS1, G1, G2, HI1, HS1, M1, M2, M3, and T1. You can register
-- instances of these types by IP address.
module Amazonka.ELBV2.RegisterTargets
  ( -- * Creating a Request
    RegisterTargets (..),
    newRegisterTargets,

    -- * Request Lenses
    registerTargets_targetGroupArn,
    registerTargets_targets,

    -- * Destructuring the Response
    RegisterTargetsResponse (..),
    newRegisterTargetsResponse,

    -- * Response Lenses
    registerTargetsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ELBV2.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newRegisterTargets' smart constructor.
data RegisterTargets = RegisterTargets'
  { -- | The Amazon Resource Name (ARN) of the target group.
    RegisterTargets -> Text
targetGroupArn :: Prelude.Text,
    -- | The targets.
    RegisterTargets -> [TargetDescription]
targets :: [TargetDescription]
  }
  deriving (RegisterTargets -> RegisterTargets -> Bool
(RegisterTargets -> RegisterTargets -> Bool)
-> (RegisterTargets -> RegisterTargets -> Bool)
-> Eq RegisterTargets
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterTargets -> RegisterTargets -> Bool
$c/= :: RegisterTargets -> RegisterTargets -> Bool
== :: RegisterTargets -> RegisterTargets -> Bool
$c== :: RegisterTargets -> RegisterTargets -> Bool
Prelude.Eq, ReadPrec [RegisterTargets]
ReadPrec RegisterTargets
Int -> ReadS RegisterTargets
ReadS [RegisterTargets]
(Int -> ReadS RegisterTargets)
-> ReadS [RegisterTargets]
-> ReadPrec RegisterTargets
-> ReadPrec [RegisterTargets]
-> Read RegisterTargets
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterTargets]
$creadListPrec :: ReadPrec [RegisterTargets]
readPrec :: ReadPrec RegisterTargets
$creadPrec :: ReadPrec RegisterTargets
readList :: ReadS [RegisterTargets]
$creadList :: ReadS [RegisterTargets]
readsPrec :: Int -> ReadS RegisterTargets
$creadsPrec :: Int -> ReadS RegisterTargets
Prelude.Read, Int -> RegisterTargets -> ShowS
[RegisterTargets] -> ShowS
RegisterTargets -> String
(Int -> RegisterTargets -> ShowS)
-> (RegisterTargets -> String)
-> ([RegisterTargets] -> ShowS)
-> Show RegisterTargets
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterTargets] -> ShowS
$cshowList :: [RegisterTargets] -> ShowS
show :: RegisterTargets -> String
$cshow :: RegisterTargets -> String
showsPrec :: Int -> RegisterTargets -> ShowS
$cshowsPrec :: Int -> RegisterTargets -> ShowS
Prelude.Show, (forall x. RegisterTargets -> Rep RegisterTargets x)
-> (forall x. Rep RegisterTargets x -> RegisterTargets)
-> Generic RegisterTargets
forall x. Rep RegisterTargets x -> RegisterTargets
forall x. RegisterTargets -> Rep RegisterTargets x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterTargets x -> RegisterTargets
$cfrom :: forall x. RegisterTargets -> Rep RegisterTargets x
Prelude.Generic)

-- |
-- Create a value of 'RegisterTargets' 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:
--
-- 'targetGroupArn', 'registerTargets_targetGroupArn' - The Amazon Resource Name (ARN) of the target group.
--
-- 'targets', 'registerTargets_targets' - The targets.
newRegisterTargets ::
  -- | 'targetGroupArn'
  Prelude.Text ->
  RegisterTargets
newRegisterTargets :: Text -> RegisterTargets
newRegisterTargets Text
pTargetGroupArn_ =
  RegisterTargets' :: Text -> [TargetDescription] -> RegisterTargets
RegisterTargets'
    { $sel:targetGroupArn:RegisterTargets' :: Text
targetGroupArn = Text
pTargetGroupArn_,
      $sel:targets:RegisterTargets' :: [TargetDescription]
targets = [TargetDescription]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The Amazon Resource Name (ARN) of the target group.
registerTargets_targetGroupArn :: Lens.Lens' RegisterTargets Prelude.Text
registerTargets_targetGroupArn :: (Text -> f Text) -> RegisterTargets -> f RegisterTargets
registerTargets_targetGroupArn = (RegisterTargets -> Text)
-> (RegisterTargets -> Text -> RegisterTargets)
-> Lens RegisterTargets RegisterTargets Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterTargets' {Text
targetGroupArn :: Text
$sel:targetGroupArn:RegisterTargets' :: RegisterTargets -> Text
targetGroupArn} -> Text
targetGroupArn) (\s :: RegisterTargets
s@RegisterTargets' {} Text
a -> RegisterTargets
s {$sel:targetGroupArn:RegisterTargets' :: Text
targetGroupArn = Text
a} :: RegisterTargets)

-- | The targets.
registerTargets_targets :: Lens.Lens' RegisterTargets [TargetDescription]
registerTargets_targets :: ([TargetDescription] -> f [TargetDescription])
-> RegisterTargets -> f RegisterTargets
registerTargets_targets = (RegisterTargets -> [TargetDescription])
-> (RegisterTargets -> [TargetDescription] -> RegisterTargets)
-> Lens
     RegisterTargets
     RegisterTargets
     [TargetDescription]
     [TargetDescription]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterTargets' {[TargetDescription]
targets :: [TargetDescription]
$sel:targets:RegisterTargets' :: RegisterTargets -> [TargetDescription]
targets} -> [TargetDescription]
targets) (\s :: RegisterTargets
s@RegisterTargets' {} [TargetDescription]
a -> RegisterTargets
s {$sel:targets:RegisterTargets' :: [TargetDescription]
targets = [TargetDescription]
a} :: RegisterTargets) (([TargetDescription] -> f [TargetDescription])
 -> RegisterTargets -> f RegisterTargets)
-> (([TargetDescription] -> f [TargetDescription])
    -> [TargetDescription] -> f [TargetDescription])
-> ([TargetDescription] -> f [TargetDescription])
-> RegisterTargets
-> f RegisterTargets
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([TargetDescription] -> f [TargetDescription])
-> [TargetDescription] -> f [TargetDescription]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest RegisterTargets where
  type
    AWSResponse RegisterTargets =
      RegisterTargetsResponse
  request :: RegisterTargets -> Request RegisterTargets
request = Service -> RegisterTargets -> Request RegisterTargets
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy RegisterTargets
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterTargets)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse RegisterTargets))
-> Logger
-> Service
-> Proxy RegisterTargets
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterTargets)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"RegisterTargetsResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> RegisterTargetsResponse
RegisterTargetsResponse'
            (Int -> RegisterTargetsResponse)
-> Either String Int -> Either String RegisterTargetsResponse
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 RegisterTargets

instance Prelude.NFData RegisterTargets

instance Core.ToHeaders RegisterTargets where
  toHeaders :: RegisterTargets -> ResponseHeaders
toHeaders = ResponseHeaders -> RegisterTargets -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery RegisterTargets where
  toQuery :: RegisterTargets -> QueryString
toQuery RegisterTargets' {[TargetDescription]
Text
targets :: [TargetDescription]
targetGroupArn :: Text
$sel:targets:RegisterTargets' :: RegisterTargets -> [TargetDescription]
$sel:targetGroupArn:RegisterTargets' :: RegisterTargets -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"RegisterTargets" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2015-12-01" :: Prelude.ByteString),
        ByteString
"TargetGroupArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
targetGroupArn,
        ByteString
"Targets" ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: ByteString -> [TargetDescription] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" [TargetDescription]
targets
      ]

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

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

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

instance Prelude.NFData RegisterTargetsResponse