{-# 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.AttachStaticIp
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Attaches a static IP address to a specific Amazon Lightsail instance.
module Amazonka.Lightsail.AttachStaticIp
  ( -- * Creating a Request
    AttachStaticIp (..),
    newAttachStaticIp,

    -- * Request Lenses
    attachStaticIp_staticIpName,
    attachStaticIp_instanceName,

    -- * Destructuring the Response
    AttachStaticIpResponse (..),
    newAttachStaticIpResponse,

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

-- |
-- Create a value of 'AttachStaticIp' 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', 'attachStaticIp_staticIpName' - The name of the static IP.
--
-- 'instanceName', 'attachStaticIp_instanceName' - The instance name to which you want to attach the static IP address.
newAttachStaticIp ::
  -- | 'staticIpName'
  Prelude.Text ->
  -- | 'instanceName'
  Prelude.Text ->
  AttachStaticIp
newAttachStaticIp :: Text -> Text -> AttachStaticIp
newAttachStaticIp Text
pStaticIpName_ Text
pInstanceName_ =
  AttachStaticIp'
    { $sel:staticIpName:AttachStaticIp' :: Text
staticIpName = Text
pStaticIpName_,
      $sel:instanceName:AttachStaticIp' :: Text
instanceName = Text
pInstanceName_
    }

-- | The name of the static IP.
attachStaticIp_staticIpName :: Lens.Lens' AttachStaticIp Prelude.Text
attachStaticIp_staticIpName :: Lens' AttachStaticIp Text
attachStaticIp_staticIpName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachStaticIp' {Text
staticIpName :: Text
$sel:staticIpName:AttachStaticIp' :: AttachStaticIp -> Text
staticIpName} -> Text
staticIpName) (\s :: AttachStaticIp
s@AttachStaticIp' {} Text
a -> AttachStaticIp
s {$sel:staticIpName:AttachStaticIp' :: Text
staticIpName = Text
a} :: AttachStaticIp)

-- | The instance name to which you want to attach the static IP address.
attachStaticIp_instanceName :: Lens.Lens' AttachStaticIp Prelude.Text
attachStaticIp_instanceName :: Lens' AttachStaticIp Text
attachStaticIp_instanceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachStaticIp' {Text
instanceName :: Text
$sel:instanceName:AttachStaticIp' :: AttachStaticIp -> Text
instanceName} -> Text
instanceName) (\s :: AttachStaticIp
s@AttachStaticIp' {} Text
a -> AttachStaticIp
s {$sel:instanceName:AttachStaticIp' :: Text
instanceName = Text
a} :: AttachStaticIp)

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

instance Prelude.NFData AttachStaticIp where
  rnf :: AttachStaticIp -> ()
rnf AttachStaticIp' {Text
instanceName :: Text
staticIpName :: Text
$sel:instanceName:AttachStaticIp' :: AttachStaticIp -> Text
$sel:staticIpName:AttachStaticIp' :: AttachStaticIp -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
staticIpName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
instanceName

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

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

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

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

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

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