{-# 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-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)
--
-- 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.Lens as Lens
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
(DetachStaticIp -> DetachStaticIp -> Bool)
-> (DetachStaticIp -> DetachStaticIp -> Bool) -> Eq DetachStaticIp
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]
(Int -> ReadS DetachStaticIp)
-> ReadS [DetachStaticIp]
-> ReadPrec DetachStaticIp
-> ReadPrec [DetachStaticIp]
-> Read 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
(Int -> DetachStaticIp -> ShowS)
-> (DetachStaticIp -> String)
-> ([DetachStaticIp] -> ShowS)
-> Show DetachStaticIp
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. DetachStaticIp -> Rep DetachStaticIp x)
-> (forall x. Rep DetachStaticIp x -> DetachStaticIp)
-> Generic DetachStaticIp
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' :: Text -> DetachStaticIp
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 :: (Text -> f Text) -> DetachStaticIp -> f DetachStaticIp
detachStaticIp_staticIpName = (DetachStaticIp -> Text)
-> (DetachStaticIp -> Text -> DetachStaticIp)
-> Lens DetachStaticIp DetachStaticIp Text Text
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 :: DetachStaticIp -> Request DetachStaticIp
request = Service -> DetachStaticIp -> Request DetachStaticIp
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DetachStaticIp
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetachStaticIp)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DetachStaticIp))
-> Logger
-> Service
-> Proxy DetachStaticIp
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetachStaticIp)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Operation] -> Int -> DetachStaticIpResponse
DetachStaticIpResponse'
            (Maybe [Operation] -> Int -> DetachStaticIpResponse)
-> Either String (Maybe [Operation])
-> Either String (Int -> DetachStaticIpResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [Operation]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"operations" Either String (Maybe (Maybe [Operation]))
-> Maybe [Operation] -> Either String (Maybe [Operation])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Operation]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> DetachStaticIpResponse)
-> Either String Int -> Either String DetachStaticIpResponse
forall (f :: * -> *) a b. Applicative f => 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 DetachStaticIp

instance Prelude.NFData DetachStaticIp

instance Core.ToHeaders DetachStaticIp where
  toHeaders :: DetachStaticIp -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DetachStaticIp -> 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
"Lightsail_20161128.DetachStaticIp" ::
                          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 DetachStaticIp where
  toJSON :: DetachStaticIp -> Value
toJSON DetachStaticIp' {Text
staticIpName :: Text
$sel:staticIpName:DetachStaticIp' :: DetachStaticIp -> 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
"staticIpName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
staticIpName)]
      )

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

instance Core.ToQuery DetachStaticIp where
  toQuery :: DetachStaticIp -> QueryString
toQuery = QueryString -> DetachStaticIp -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(DetachStaticIpResponse -> DetachStaticIpResponse -> Bool)
-> (DetachStaticIpResponse -> DetachStaticIpResponse -> Bool)
-> Eq DetachStaticIpResponse
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]
(Int -> ReadS DetachStaticIpResponse)
-> ReadS [DetachStaticIpResponse]
-> ReadPrec DetachStaticIpResponse
-> ReadPrec [DetachStaticIpResponse]
-> Read 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
(Int -> DetachStaticIpResponse -> ShowS)
-> (DetachStaticIpResponse -> String)
-> ([DetachStaticIpResponse] -> ShowS)
-> Show DetachStaticIpResponse
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. DetachStaticIpResponse -> Rep DetachStaticIpResponse x)
-> (forall x.
    Rep DetachStaticIpResponse x -> DetachStaticIpResponse)
-> Generic DetachStaticIpResponse
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' :: Maybe [Operation] -> Int -> DetachStaticIpResponse
DetachStaticIpResponse'
    { $sel:operations:DetachStaticIpResponse' :: Maybe [Operation]
operations =
        Maybe [Operation]
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 :: (Maybe [Operation] -> f (Maybe [Operation]))
-> DetachStaticIpResponse -> f DetachStaticIpResponse
detachStaticIpResponse_operations = (DetachStaticIpResponse -> Maybe [Operation])
-> (DetachStaticIpResponse
    -> Maybe [Operation] -> DetachStaticIpResponse)
-> Lens
     DetachStaticIpResponse
     DetachStaticIpResponse
     (Maybe [Operation])
     (Maybe [Operation])
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) ((Maybe [Operation] -> f (Maybe [Operation]))
 -> DetachStaticIpResponse -> f DetachStaticIpResponse)
-> ((Maybe [Operation] -> f (Maybe [Operation]))
    -> Maybe [Operation] -> f (Maybe [Operation]))
-> (Maybe [Operation] -> f (Maybe [Operation]))
-> DetachStaticIpResponse
-> f DetachStaticIpResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Operation] [Operation] [Operation] [Operation]
-> Iso
     (Maybe [Operation])
     (Maybe [Operation])
     (Maybe [Operation])
     (Maybe [Operation])
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 AnIso [Operation] [Operation] [Operation] [Operation]
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 :: (Int -> f Int)
-> DetachStaticIpResponse -> f DetachStaticIpResponse
detachStaticIpResponse_httpStatus = (DetachStaticIpResponse -> Int)
-> (DetachStaticIpResponse -> Int -> DetachStaticIpResponse)
-> Lens DetachStaticIpResponse DetachStaticIpResponse Int Int
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