{-# 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.Lightsail.DetachInstancesFromLoadBalancer
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Detaches the specified instances from a Lightsail load balancer.
--
-- This operation waits until the instances are no longer needed before
-- they are detached from the load balancer.
--
-- The @detach instances from load balancer@ operation supports tag-based
-- access control via resource tags applied to the resource identified by
-- @load balancer name@. For more information, see the
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-controlling-access-using-tags Amazon Lightsail Developer Guide>.
module Amazonka.Lightsail.DetachInstancesFromLoadBalancer
  ( -- * Creating a Request
    DetachInstancesFromLoadBalancer (..),
    newDetachInstancesFromLoadBalancer,

    -- * Request Lenses
    detachInstancesFromLoadBalancer_loadBalancerName,
    detachInstancesFromLoadBalancer_instanceNames,

    -- * Destructuring the Response
    DetachInstancesFromLoadBalancerResponse (..),
    newDetachInstancesFromLoadBalancerResponse,

    -- * Response Lenses
    detachInstancesFromLoadBalancerResponse_operations,
    detachInstancesFromLoadBalancerResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lightsail.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDetachInstancesFromLoadBalancer' smart constructor.
data DetachInstancesFromLoadBalancer = DetachInstancesFromLoadBalancer'
  { -- | The name of the Lightsail load balancer.
    DetachInstancesFromLoadBalancer -> Text
loadBalancerName :: Prelude.Text,
    -- | An array of strings containing the names of the instances you want to
    -- detach from the load balancer.
    DetachInstancesFromLoadBalancer -> [Text]
instanceNames :: [Prelude.Text]
  }
  deriving (DetachInstancesFromLoadBalancer
-> DetachInstancesFromLoadBalancer -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetachInstancesFromLoadBalancer
-> DetachInstancesFromLoadBalancer -> Bool
$c/= :: DetachInstancesFromLoadBalancer
-> DetachInstancesFromLoadBalancer -> Bool
== :: DetachInstancesFromLoadBalancer
-> DetachInstancesFromLoadBalancer -> Bool
$c== :: DetachInstancesFromLoadBalancer
-> DetachInstancesFromLoadBalancer -> Bool
Prelude.Eq, ReadPrec [DetachInstancesFromLoadBalancer]
ReadPrec DetachInstancesFromLoadBalancer
Int -> ReadS DetachInstancesFromLoadBalancer
ReadS [DetachInstancesFromLoadBalancer]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetachInstancesFromLoadBalancer]
$creadListPrec :: ReadPrec [DetachInstancesFromLoadBalancer]
readPrec :: ReadPrec DetachInstancesFromLoadBalancer
$creadPrec :: ReadPrec DetachInstancesFromLoadBalancer
readList :: ReadS [DetachInstancesFromLoadBalancer]
$creadList :: ReadS [DetachInstancesFromLoadBalancer]
readsPrec :: Int -> ReadS DetachInstancesFromLoadBalancer
$creadsPrec :: Int -> ReadS DetachInstancesFromLoadBalancer
Prelude.Read, Int -> DetachInstancesFromLoadBalancer -> ShowS
[DetachInstancesFromLoadBalancer] -> ShowS
DetachInstancesFromLoadBalancer -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetachInstancesFromLoadBalancer] -> ShowS
$cshowList :: [DetachInstancesFromLoadBalancer] -> ShowS
show :: DetachInstancesFromLoadBalancer -> String
$cshow :: DetachInstancesFromLoadBalancer -> String
showsPrec :: Int -> DetachInstancesFromLoadBalancer -> ShowS
$cshowsPrec :: Int -> DetachInstancesFromLoadBalancer -> ShowS
Prelude.Show, forall x.
Rep DetachInstancesFromLoadBalancer x
-> DetachInstancesFromLoadBalancer
forall x.
DetachInstancesFromLoadBalancer
-> Rep DetachInstancesFromLoadBalancer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DetachInstancesFromLoadBalancer x
-> DetachInstancesFromLoadBalancer
$cfrom :: forall x.
DetachInstancesFromLoadBalancer
-> Rep DetachInstancesFromLoadBalancer x
Prelude.Generic)

-- |
-- Create a value of 'DetachInstancesFromLoadBalancer' 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:
--
-- 'loadBalancerName', 'detachInstancesFromLoadBalancer_loadBalancerName' - The name of the Lightsail load balancer.
--
-- 'instanceNames', 'detachInstancesFromLoadBalancer_instanceNames' - An array of strings containing the names of the instances you want to
-- detach from the load balancer.
newDetachInstancesFromLoadBalancer ::
  -- | 'loadBalancerName'
  Prelude.Text ->
  DetachInstancesFromLoadBalancer
newDetachInstancesFromLoadBalancer :: Text -> DetachInstancesFromLoadBalancer
newDetachInstancesFromLoadBalancer Text
pLoadBalancerName_ =
  DetachInstancesFromLoadBalancer'
    { $sel:loadBalancerName:DetachInstancesFromLoadBalancer' :: Text
loadBalancerName =
        Text
pLoadBalancerName_,
      $sel:instanceNames:DetachInstancesFromLoadBalancer' :: [Text]
instanceNames = forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the Lightsail load balancer.
detachInstancesFromLoadBalancer_loadBalancerName :: Lens.Lens' DetachInstancesFromLoadBalancer Prelude.Text
detachInstancesFromLoadBalancer_loadBalancerName :: Lens' DetachInstancesFromLoadBalancer Text
detachInstancesFromLoadBalancer_loadBalancerName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachInstancesFromLoadBalancer' {Text
loadBalancerName :: Text
$sel:loadBalancerName:DetachInstancesFromLoadBalancer' :: DetachInstancesFromLoadBalancer -> Text
loadBalancerName} -> Text
loadBalancerName) (\s :: DetachInstancesFromLoadBalancer
s@DetachInstancesFromLoadBalancer' {} Text
a -> DetachInstancesFromLoadBalancer
s {$sel:loadBalancerName:DetachInstancesFromLoadBalancer' :: Text
loadBalancerName = Text
a} :: DetachInstancesFromLoadBalancer)

-- | An array of strings containing the names of the instances you want to
-- detach from the load balancer.
detachInstancesFromLoadBalancer_instanceNames :: Lens.Lens' DetachInstancesFromLoadBalancer [Prelude.Text]
detachInstancesFromLoadBalancer_instanceNames :: Lens' DetachInstancesFromLoadBalancer [Text]
detachInstancesFromLoadBalancer_instanceNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachInstancesFromLoadBalancer' {[Text]
instanceNames :: [Text]
$sel:instanceNames:DetachInstancesFromLoadBalancer' :: DetachInstancesFromLoadBalancer -> [Text]
instanceNames} -> [Text]
instanceNames) (\s :: DetachInstancesFromLoadBalancer
s@DetachInstancesFromLoadBalancer' {} [Text]
a -> DetachInstancesFromLoadBalancer
s {$sel:instanceNames:DetachInstancesFromLoadBalancer' :: [Text]
instanceNames = [Text]
a} :: DetachInstancesFromLoadBalancer) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance
  Core.AWSRequest
    DetachInstancesFromLoadBalancer
  where
  type
    AWSResponse DetachInstancesFromLoadBalancer =
      DetachInstancesFromLoadBalancerResponse
  request :: (Service -> Service)
-> DetachInstancesFromLoadBalancer
-> Request DetachInstancesFromLoadBalancer
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 DetachInstancesFromLoadBalancer
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse DetachInstancesFromLoadBalancer)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Operation] -> Int -> DetachInstancesFromLoadBalancerResponse
DetachInstancesFromLoadBalancerResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"operations" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => 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
    DetachInstancesFromLoadBalancer
  where
  hashWithSalt :: Int -> DetachInstancesFromLoadBalancer -> Int
hashWithSalt
    Int
_salt
    DetachInstancesFromLoadBalancer' {[Text]
Text
instanceNames :: [Text]
loadBalancerName :: Text
$sel:instanceNames:DetachInstancesFromLoadBalancer' :: DetachInstancesFromLoadBalancer -> [Text]
$sel:loadBalancerName:DetachInstancesFromLoadBalancer' :: DetachInstancesFromLoadBalancer -> Text
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
loadBalancerName
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
instanceNames

instance
  Prelude.NFData
    DetachInstancesFromLoadBalancer
  where
  rnf :: DetachInstancesFromLoadBalancer -> ()
rnf DetachInstancesFromLoadBalancer' {[Text]
Text
instanceNames :: [Text]
loadBalancerName :: Text
$sel:instanceNames:DetachInstancesFromLoadBalancer' :: DetachInstancesFromLoadBalancer -> [Text]
$sel:loadBalancerName:DetachInstancesFromLoadBalancer' :: DetachInstancesFromLoadBalancer -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
loadBalancerName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
instanceNames

instance
  Data.ToHeaders
    DetachInstancesFromLoadBalancer
  where
  toHeaders :: DetachInstancesFromLoadBalancer -> 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
"Lightsail_20161128.DetachInstancesFromLoadBalancer" ::
                          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 DetachInstancesFromLoadBalancer where
  toJSON :: DetachInstancesFromLoadBalancer -> Value
toJSON DetachInstancesFromLoadBalancer' {[Text]
Text
instanceNames :: [Text]
loadBalancerName :: Text
$sel:instanceNames:DetachInstancesFromLoadBalancer' :: DetachInstancesFromLoadBalancer -> [Text]
$sel:loadBalancerName:DetachInstancesFromLoadBalancer' :: DetachInstancesFromLoadBalancer -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"loadBalancerName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
loadBalancerName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"instanceNames" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
instanceNames)
          ]
      )

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

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

-- | /See:/ 'newDetachInstancesFromLoadBalancerResponse' smart constructor.
data DetachInstancesFromLoadBalancerResponse = DetachInstancesFromLoadBalancerResponse'
  { -- | An array of objects that describe the result of the action, such as the
    -- status of the request, the timestamp of the request, and the resources
    -- affected by the request.
    DetachInstancesFromLoadBalancerResponse -> Maybe [Operation]
operations :: Prelude.Maybe [Operation],
    -- | The response's http status code.
    DetachInstancesFromLoadBalancerResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DetachInstancesFromLoadBalancerResponse
-> DetachInstancesFromLoadBalancerResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetachInstancesFromLoadBalancerResponse
-> DetachInstancesFromLoadBalancerResponse -> Bool
$c/= :: DetachInstancesFromLoadBalancerResponse
-> DetachInstancesFromLoadBalancerResponse -> Bool
== :: DetachInstancesFromLoadBalancerResponse
-> DetachInstancesFromLoadBalancerResponse -> Bool
$c== :: DetachInstancesFromLoadBalancerResponse
-> DetachInstancesFromLoadBalancerResponse -> Bool
Prelude.Eq, ReadPrec [DetachInstancesFromLoadBalancerResponse]
ReadPrec DetachInstancesFromLoadBalancerResponse
Int -> ReadS DetachInstancesFromLoadBalancerResponse
ReadS [DetachInstancesFromLoadBalancerResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetachInstancesFromLoadBalancerResponse]
$creadListPrec :: ReadPrec [DetachInstancesFromLoadBalancerResponse]
readPrec :: ReadPrec DetachInstancesFromLoadBalancerResponse
$creadPrec :: ReadPrec DetachInstancesFromLoadBalancerResponse
readList :: ReadS [DetachInstancesFromLoadBalancerResponse]
$creadList :: ReadS [DetachInstancesFromLoadBalancerResponse]
readsPrec :: Int -> ReadS DetachInstancesFromLoadBalancerResponse
$creadsPrec :: Int -> ReadS DetachInstancesFromLoadBalancerResponse
Prelude.Read, Int -> DetachInstancesFromLoadBalancerResponse -> ShowS
[DetachInstancesFromLoadBalancerResponse] -> ShowS
DetachInstancesFromLoadBalancerResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetachInstancesFromLoadBalancerResponse] -> ShowS
$cshowList :: [DetachInstancesFromLoadBalancerResponse] -> ShowS
show :: DetachInstancesFromLoadBalancerResponse -> String
$cshow :: DetachInstancesFromLoadBalancerResponse -> String
showsPrec :: Int -> DetachInstancesFromLoadBalancerResponse -> ShowS
$cshowsPrec :: Int -> DetachInstancesFromLoadBalancerResponse -> ShowS
Prelude.Show, forall x.
Rep DetachInstancesFromLoadBalancerResponse x
-> DetachInstancesFromLoadBalancerResponse
forall x.
DetachInstancesFromLoadBalancerResponse
-> Rep DetachInstancesFromLoadBalancerResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DetachInstancesFromLoadBalancerResponse x
-> DetachInstancesFromLoadBalancerResponse
$cfrom :: forall x.
DetachInstancesFromLoadBalancerResponse
-> Rep DetachInstancesFromLoadBalancerResponse x
Prelude.Generic)

-- |
-- Create a value of 'DetachInstancesFromLoadBalancerResponse' 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:
--
-- 'operations', 'detachInstancesFromLoadBalancerResponse_operations' - An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
--
-- 'httpStatus', 'detachInstancesFromLoadBalancerResponse_httpStatus' - The response's http status code.
newDetachInstancesFromLoadBalancerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DetachInstancesFromLoadBalancerResponse
newDetachInstancesFromLoadBalancerResponse :: Int -> DetachInstancesFromLoadBalancerResponse
newDetachInstancesFromLoadBalancerResponse
  Int
pHttpStatus_ =
    DetachInstancesFromLoadBalancerResponse'
      { $sel:operations:DetachInstancesFromLoadBalancerResponse' :: Maybe [Operation]
operations =
          forall a. Maybe a
Prelude.Nothing,
        $sel:httpStatus:DetachInstancesFromLoadBalancerResponse' :: Int
httpStatus = Int
pHttpStatus_
      }

-- | An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
detachInstancesFromLoadBalancerResponse_operations :: Lens.Lens' DetachInstancesFromLoadBalancerResponse (Prelude.Maybe [Operation])
detachInstancesFromLoadBalancerResponse_operations :: Lens' DetachInstancesFromLoadBalancerResponse (Maybe [Operation])
detachInstancesFromLoadBalancerResponse_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachInstancesFromLoadBalancerResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:DetachInstancesFromLoadBalancerResponse' :: DetachInstancesFromLoadBalancerResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: DetachInstancesFromLoadBalancerResponse
s@DetachInstancesFromLoadBalancerResponse' {} Maybe [Operation]
a -> DetachInstancesFromLoadBalancerResponse
s {$sel:operations:DetachInstancesFromLoadBalancerResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: DetachInstancesFromLoadBalancerResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.NFData
    DetachInstancesFromLoadBalancerResponse
  where
  rnf :: DetachInstancesFromLoadBalancerResponse -> ()
rnf DetachInstancesFromLoadBalancerResponse' {Int
Maybe [Operation]
httpStatus :: Int
operations :: Maybe [Operation]
$sel:httpStatus:DetachInstancesFromLoadBalancerResponse' :: DetachInstancesFromLoadBalancerResponse -> Int
$sel:operations:DetachInstancesFromLoadBalancerResponse' :: DetachInstancesFromLoadBalancerResponse -> Maybe [Operation]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Operation]
operations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus