{-# 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-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)
--
-- 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 AWS billing cycle. To determine if you can update
-- a bucket\'s bundle, use the 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.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:/ '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 GetBucketBundles action to get a list of bundle IDs that you can
    -- specify.
    UpdateBucketBundle -> Text
bundleId :: Prelude.Text
  }
  deriving (UpdateBucketBundle -> UpdateBucketBundle -> Bool
(UpdateBucketBundle -> UpdateBucketBundle -> Bool)
-> (UpdateBucketBundle -> UpdateBucketBundle -> Bool)
-> Eq UpdateBucketBundle
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]
(Int -> ReadS UpdateBucketBundle)
-> ReadS [UpdateBucketBundle]
-> ReadPrec UpdateBucketBundle
-> ReadPrec [UpdateBucketBundle]
-> Read 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
(Int -> UpdateBucketBundle -> ShowS)
-> (UpdateBucketBundle -> String)
-> ([UpdateBucketBundle] -> ShowS)
-> Show UpdateBucketBundle
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. UpdateBucketBundle -> Rep UpdateBucketBundle x)
-> (forall x. Rep UpdateBucketBundle x -> UpdateBucketBundle)
-> Generic UpdateBucketBundle
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 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' :: Text -> Text -> UpdateBucketBundle
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 :: (Text -> f Text) -> UpdateBucketBundle -> f UpdateBucketBundle
updateBucketBundle_bucketName = (UpdateBucketBundle -> Text)
-> (UpdateBucketBundle -> Text -> UpdateBucketBundle)
-> Lens UpdateBucketBundle UpdateBucketBundle Text Text
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 GetBucketBundles action to get a list of bundle IDs that you can
-- specify.
updateBucketBundle_bundleId :: Lens.Lens' UpdateBucketBundle Prelude.Text
updateBucketBundle_bundleId :: (Text -> f Text) -> UpdateBucketBundle -> f UpdateBucketBundle
updateBucketBundle_bundleId = (UpdateBucketBundle -> Text)
-> (UpdateBucketBundle -> Text -> UpdateBucketBundle)
-> Lens UpdateBucketBundle UpdateBucketBundle Text Text
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 :: UpdateBucketBundle -> Request UpdateBucketBundle
request = Service -> UpdateBucketBundle -> Request UpdateBucketBundle
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateBucketBundle
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateBucketBundle)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse UpdateBucketBundle))
-> Logger
-> Service
-> Proxy UpdateBucketBundle
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateBucketBundle)))
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 -> UpdateBucketBundleResponse
UpdateBucketBundleResponse'
            (Maybe [Operation] -> Int -> UpdateBucketBundleResponse)
-> Either String (Maybe [Operation])
-> Either String (Int -> UpdateBucketBundleResponse)
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 -> UpdateBucketBundleResponse)
-> Either String Int -> Either String UpdateBucketBundleResponse
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 UpdateBucketBundle

instance Prelude.NFData UpdateBucketBundle

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

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

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