{-# 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.UpdateBucketBundle
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates the bundle, or storage plan, of an existing Amazon Lightsail
-- bucket.
--
-- A bucket bundle specifies the monthly cost, storage space, and data
-- transfer quota for a bucket. You can update a bucket\'s bundle only one
-- time within a monthly Amazon Web Services billing cycle. To determine if
-- you can update a bucket\'s bundle, use the
-- <https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetBuckets.html GetBuckets>
-- action. The @ableToUpdateBundle@ parameter in the response will indicate
-- whether you can currently update a bucket\'s bundle.
--
-- Update a bucket\'s bundle if it\'s consistently going over its storage
-- space or data transfer quota, or if a bucket\'s usage is consistently in
-- the lower range of its storage space or data transfer quota. Due to the
-- unpredictable usage fluctuations that a bucket might experience, we
-- strongly recommend that you update a bucket\'s bundle only as a
-- long-term strategy, instead of as a short-term, monthly cost-cutting
-- measure. Choose a bucket bundle that will provide the bucket with ample
-- storage space and data transfer for a long time to come.
module Amazonka.Lightsail.UpdateBucketBundle
  ( -- * Creating a Request
    UpdateBucketBundle (..),
    newUpdateBucketBundle,

    -- * Request Lenses
    updateBucketBundle_bucketName,
    updateBucketBundle_bundleId,

    -- * Destructuring the Response
    UpdateBucketBundleResponse (..),
    newUpdateBucketBundleResponse,

    -- * Response Lenses
    updateBucketBundleResponse_operations,
    updateBucketBundleResponse_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:/ 'newUpdateBucketBundle' smart constructor.
data UpdateBucketBundle = UpdateBucketBundle'
  { -- | The name of the bucket for which to update the bundle.
    UpdateBucketBundle -> Text
bucketName :: Prelude.Text,
    -- | The ID of the new bundle to apply to the bucket.
    --
    -- Use the
    -- <https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetBucketBundles.html GetBucketBundles>
    -- action to get a list of bundle IDs that you can specify.
    UpdateBucketBundle -> Text
bundleId :: Prelude.Text
  }
  deriving (UpdateBucketBundle -> UpdateBucketBundle -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateBucketBundle -> UpdateBucketBundle -> Bool
$c/= :: UpdateBucketBundle -> UpdateBucketBundle -> Bool
== :: UpdateBucketBundle -> UpdateBucketBundle -> Bool
$c== :: UpdateBucketBundle -> UpdateBucketBundle -> Bool
Prelude.Eq, ReadPrec [UpdateBucketBundle]
ReadPrec UpdateBucketBundle
Int -> ReadS UpdateBucketBundle
ReadS [UpdateBucketBundle]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateBucketBundle]
$creadListPrec :: ReadPrec [UpdateBucketBundle]
readPrec :: ReadPrec UpdateBucketBundle
$creadPrec :: ReadPrec UpdateBucketBundle
readList :: ReadS [UpdateBucketBundle]
$creadList :: ReadS [UpdateBucketBundle]
readsPrec :: Int -> ReadS UpdateBucketBundle
$creadsPrec :: Int -> ReadS UpdateBucketBundle
Prelude.Read, Int -> UpdateBucketBundle -> ShowS
[UpdateBucketBundle] -> ShowS
UpdateBucketBundle -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateBucketBundle] -> ShowS
$cshowList :: [UpdateBucketBundle] -> ShowS
show :: UpdateBucketBundle -> String
$cshow :: UpdateBucketBundle -> String
showsPrec :: Int -> UpdateBucketBundle -> ShowS
$cshowsPrec :: Int -> UpdateBucketBundle -> ShowS
Prelude.Show, forall x. Rep UpdateBucketBundle x -> UpdateBucketBundle
forall x. UpdateBucketBundle -> Rep UpdateBucketBundle x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateBucketBundle x -> UpdateBucketBundle
$cfrom :: forall x. UpdateBucketBundle -> Rep UpdateBucketBundle x
Prelude.Generic)

-- |
-- Create a value of 'UpdateBucketBundle' 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:
--
-- 'bucketName', 'updateBucketBundle_bucketName' - The name of the bucket for which to update the bundle.
--
-- 'bundleId', 'updateBucketBundle_bundleId' - The ID of the new bundle to apply to the bucket.
--
-- Use the
-- <https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetBucketBundles.html GetBucketBundles>
-- action to get a list of bundle IDs that you can specify.
newUpdateBucketBundle ::
  -- | 'bucketName'
  Prelude.Text ->
  -- | 'bundleId'
  Prelude.Text ->
  UpdateBucketBundle
newUpdateBucketBundle :: Text -> Text -> UpdateBucketBundle
newUpdateBucketBundle Text
pBucketName_ Text
pBundleId_ =
  UpdateBucketBundle'
    { $sel:bucketName:UpdateBucketBundle' :: Text
bucketName = Text
pBucketName_,
      $sel:bundleId:UpdateBucketBundle' :: Text
bundleId = Text
pBundleId_
    }

-- | The name of the bucket for which to update the bundle.
updateBucketBundle_bucketName :: Lens.Lens' UpdateBucketBundle Prelude.Text
updateBucketBundle_bucketName :: Lens' UpdateBucketBundle Text
updateBucketBundle_bucketName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateBucketBundle' {Text
bucketName :: Text
$sel:bucketName:UpdateBucketBundle' :: UpdateBucketBundle -> Text
bucketName} -> Text
bucketName) (\s :: UpdateBucketBundle
s@UpdateBucketBundle' {} Text
a -> UpdateBucketBundle
s {$sel:bucketName:UpdateBucketBundle' :: Text
bucketName = Text
a} :: UpdateBucketBundle)

-- | The ID of the new bundle to apply to the bucket.
--
-- Use the
-- <https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetBucketBundles.html GetBucketBundles>
-- action to get a list of bundle IDs that you can specify.
updateBucketBundle_bundleId :: Lens.Lens' UpdateBucketBundle Prelude.Text
updateBucketBundle_bundleId :: Lens' UpdateBucketBundle Text
updateBucketBundle_bundleId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateBucketBundle' {Text
bundleId :: Text
$sel:bundleId:UpdateBucketBundle' :: UpdateBucketBundle -> Text
bundleId} -> Text
bundleId) (\s :: UpdateBucketBundle
s@UpdateBucketBundle' {} Text
a -> UpdateBucketBundle
s {$sel:bundleId:UpdateBucketBundle' :: Text
bundleId = Text
a} :: UpdateBucketBundle)

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

instance Prelude.NFData UpdateBucketBundle where
  rnf :: UpdateBucketBundle -> ()
rnf UpdateBucketBundle' {Text
bundleId :: Text
bucketName :: Text
$sel:bundleId:UpdateBucketBundle' :: UpdateBucketBundle -> Text
$sel:bucketName:UpdateBucketBundle' :: UpdateBucketBundle -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
bucketName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
bundleId

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

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

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

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

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

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