{-# 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.DetachStaticIp
-- 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 a static IP from the Amazon Lightsail instance to which it is
-- attached.
module Amazonka.Lightsail.DetachStaticIp
  ( -- * Creating a Request
    DetachStaticIp (..),
    newDetachStaticIp,

    -- * Request Lenses
    detachStaticIp_staticIpName,

    -- * Destructuring the Response
    DetachStaticIpResponse (..),
    newDetachStaticIpResponse,

    -- * Response Lenses
    detachStaticIpResponse_operations,
    detachStaticIpResponse_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:/ 'newDetachStaticIp' smart constructor.
data DetachStaticIp = DetachStaticIp'
  { -- | The name of the static IP to detach from the instance.
    DetachStaticIp -> Text
staticIpName :: Prelude.Text
  }
  deriving (DetachStaticIp -> DetachStaticIp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetachStaticIp -> DetachStaticIp -> Bool
$c/= :: DetachStaticIp -> DetachStaticIp -> Bool
== :: DetachStaticIp -> DetachStaticIp -> Bool
$c== :: DetachStaticIp -> DetachStaticIp -> Bool
Prelude.Eq, ReadPrec [DetachStaticIp]
ReadPrec DetachStaticIp
Int -> ReadS DetachStaticIp
ReadS [DetachStaticIp]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetachStaticIp]
$creadListPrec :: ReadPrec [DetachStaticIp]
readPrec :: ReadPrec DetachStaticIp
$creadPrec :: ReadPrec DetachStaticIp
readList :: ReadS [DetachStaticIp]
$creadList :: ReadS [DetachStaticIp]
readsPrec :: Int -> ReadS DetachStaticIp
$creadsPrec :: Int -> ReadS DetachStaticIp
Prelude.Read, Int -> DetachStaticIp -> ShowS
[DetachStaticIp] -> ShowS
DetachStaticIp -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetachStaticIp] -> ShowS
$cshowList :: [DetachStaticIp] -> ShowS
show :: DetachStaticIp -> String
$cshow :: DetachStaticIp -> String
showsPrec :: Int -> DetachStaticIp -> ShowS
$cshowsPrec :: Int -> DetachStaticIp -> ShowS
Prelude.Show, forall x. Rep DetachStaticIp x -> DetachStaticIp
forall x. DetachStaticIp -> Rep DetachStaticIp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetachStaticIp x -> DetachStaticIp
$cfrom :: forall x. DetachStaticIp -> Rep DetachStaticIp x
Prelude.Generic)

-- |
-- Create a value of 'DetachStaticIp' 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:
--
-- 'staticIpName', 'detachStaticIp_staticIpName' - The name of the static IP to detach from the instance.
newDetachStaticIp ::
  -- | 'staticIpName'
  Prelude.Text ->
  DetachStaticIp
newDetachStaticIp :: Text -> DetachStaticIp
newDetachStaticIp Text
pStaticIpName_ =
  DetachStaticIp' {$sel:staticIpName:DetachStaticIp' :: Text
staticIpName = Text
pStaticIpName_}

-- | The name of the static IP to detach from the instance.
detachStaticIp_staticIpName :: Lens.Lens' DetachStaticIp Prelude.Text
detachStaticIp_staticIpName :: Lens' DetachStaticIp Text
detachStaticIp_staticIpName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachStaticIp' {Text
staticIpName :: Text
$sel:staticIpName:DetachStaticIp' :: DetachStaticIp -> Text
staticIpName} -> Text
staticIpName) (\s :: DetachStaticIp
s@DetachStaticIp' {} Text
a -> DetachStaticIp
s {$sel:staticIpName:DetachStaticIp' :: Text
staticIpName = Text
a} :: DetachStaticIp)

instance Core.AWSRequest DetachStaticIp where
  type
    AWSResponse DetachStaticIp =
      DetachStaticIpResponse
  request :: (Service -> Service) -> DetachStaticIp -> Request DetachStaticIp
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 DetachStaticIp
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetachStaticIp)))
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 -> DetachStaticIpResponse
DetachStaticIpResponse'
            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 DetachStaticIp where
  hashWithSalt :: Int -> DetachStaticIp -> Int
hashWithSalt Int
_salt DetachStaticIp' {Text
staticIpName :: Text
$sel:staticIpName:DetachStaticIp' :: DetachStaticIp -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
staticIpName

instance Prelude.NFData DetachStaticIp where
  rnf :: DetachStaticIp -> ()
rnf DetachStaticIp' {Text
staticIpName :: Text
$sel:staticIpName:DetachStaticIp' :: DetachStaticIp -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
staticIpName

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

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

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

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

-- |
-- Create a value of 'DetachStaticIpResponse' 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', 'detachStaticIpResponse_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', 'detachStaticIpResponse_httpStatus' - The response's http status code.
newDetachStaticIpResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DetachStaticIpResponse
newDetachStaticIpResponse :: Int -> DetachStaticIpResponse
newDetachStaticIpResponse Int
pHttpStatus_ =
  DetachStaticIpResponse'
    { $sel:operations:DetachStaticIpResponse' :: Maybe [Operation]
operations =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DetachStaticIpResponse' :: 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.
detachStaticIpResponse_operations :: Lens.Lens' DetachStaticIpResponse (Prelude.Maybe [Operation])
detachStaticIpResponse_operations :: Lens' DetachStaticIpResponse (Maybe [Operation])
detachStaticIpResponse_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachStaticIpResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:DetachStaticIpResponse' :: DetachStaticIpResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: DetachStaticIpResponse
s@DetachStaticIpResponse' {} Maybe [Operation]
a -> DetachStaticIpResponse
s {$sel:operations:DetachStaticIpResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: DetachStaticIpResponse) 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.
detachStaticIpResponse_httpStatus :: Lens.Lens' DetachStaticIpResponse Prelude.Int
detachStaticIpResponse_httpStatus :: Lens' DetachStaticIpResponse Int
detachStaticIpResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachStaticIpResponse' {Int
httpStatus :: Int
$sel:httpStatus:DetachStaticIpResponse' :: DetachStaticIpResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DetachStaticIpResponse
s@DetachStaticIpResponse' {} Int
a -> DetachStaticIpResponse
s {$sel:httpStatus:DetachStaticIpResponse' :: Int
httpStatus = Int
a} :: DetachStaticIpResponse)

instance Prelude.NFData DetachStaticIpResponse where
  rnf :: DetachStaticIpResponse -> ()
rnf DetachStaticIpResponse' {Int
Maybe [Operation]
httpStatus :: Int
operations :: Maybe [Operation]
$sel:httpStatus:DetachStaticIpResponse' :: DetachStaticIpResponse -> Int
$sel:operations:DetachStaticIpResponse' :: DetachStaticIpResponse -> 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