{-# 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.Budgets.UpdateBudget
-- 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 a budget. You can change every part of a budget except for the
-- @budgetName@ and the @calculatedSpend@. When you modify a budget, the
-- @calculatedSpend@ drops to zero until Amazon Web Services has new usage
-- data to use for forecasting.
--
-- Only one of @BudgetLimit@ or @PlannedBudgetLimits@ can be present in the
-- syntax at one time. Use the syntax that matches your case. The Request
-- Syntax section shows the @BudgetLimit@ syntax. For
-- @PlannedBudgetLimits@, see the
-- <https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_budgets_UpdateBudget.html#API_UpdateBudget_Examples Examples>
-- section.
module Amazonka.Budgets.UpdateBudget
  ( -- * Creating a Request
    UpdateBudget (..),
    newUpdateBudget,

    -- * Request Lenses
    updateBudget_accountId,
    updateBudget_newBudget,

    -- * Destructuring the Response
    UpdateBudgetResponse (..),
    newUpdateBudgetResponse,

    -- * Response Lenses
    updateBudgetResponse_httpStatus,
  )
where

import Amazonka.Budgets.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Request of UpdateBudget
--
-- /See:/ 'newUpdateBudget' smart constructor.
data UpdateBudget = UpdateBudget'
  { -- | The @accountId@ that is associated with the budget that you want to
    -- update.
    UpdateBudget -> Text
accountId :: Prelude.Text,
    -- | The budget that you want to update your budget to.
    UpdateBudget -> Budget
newBudget' :: Budget
  }
  deriving (UpdateBudget -> UpdateBudget -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateBudget -> UpdateBudget -> Bool
$c/= :: UpdateBudget -> UpdateBudget -> Bool
== :: UpdateBudget -> UpdateBudget -> Bool
$c== :: UpdateBudget -> UpdateBudget -> Bool
Prelude.Eq, ReadPrec [UpdateBudget]
ReadPrec UpdateBudget
Int -> ReadS UpdateBudget
ReadS [UpdateBudget]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateBudget]
$creadListPrec :: ReadPrec [UpdateBudget]
readPrec :: ReadPrec UpdateBudget
$creadPrec :: ReadPrec UpdateBudget
readList :: ReadS [UpdateBudget]
$creadList :: ReadS [UpdateBudget]
readsPrec :: Int -> ReadS UpdateBudget
$creadsPrec :: Int -> ReadS UpdateBudget
Prelude.Read, Int -> UpdateBudget -> ShowS
[UpdateBudget] -> ShowS
UpdateBudget -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateBudget] -> ShowS
$cshowList :: [UpdateBudget] -> ShowS
show :: UpdateBudget -> String
$cshow :: UpdateBudget -> String
showsPrec :: Int -> UpdateBudget -> ShowS
$cshowsPrec :: Int -> UpdateBudget -> ShowS
Prelude.Show, forall x. Rep UpdateBudget x -> UpdateBudget
forall x. UpdateBudget -> Rep UpdateBudget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateBudget x -> UpdateBudget
$cfrom :: forall x. UpdateBudget -> Rep UpdateBudget x
Prelude.Generic)

-- |
-- Create a value of 'UpdateBudget' 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:
--
-- 'accountId', 'updateBudget_accountId' - The @accountId@ that is associated with the budget that you want to
-- update.
--
-- 'newBudget'', 'updateBudget_newBudget' - The budget that you want to update your budget to.
newUpdateBudget ::
  -- | 'accountId'
  Prelude.Text ->
  -- | 'newBudget''
  Budget ->
  UpdateBudget
newUpdateBudget :: Text -> Budget -> UpdateBudget
newUpdateBudget Text
pAccountId_ Budget
pNewBudget_ =
  UpdateBudget'
    { $sel:accountId:UpdateBudget' :: Text
accountId = Text
pAccountId_,
      $sel:newBudget':UpdateBudget' :: Budget
newBudget' = Budget
pNewBudget_
    }

-- | The @accountId@ that is associated with the budget that you want to
-- update.
updateBudget_accountId :: Lens.Lens' UpdateBudget Prelude.Text
updateBudget_accountId :: Lens' UpdateBudget Text
updateBudget_accountId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateBudget' {Text
accountId :: Text
$sel:accountId:UpdateBudget' :: UpdateBudget -> Text
accountId} -> Text
accountId) (\s :: UpdateBudget
s@UpdateBudget' {} Text
a -> UpdateBudget
s {$sel:accountId:UpdateBudget' :: Text
accountId = Text
a} :: UpdateBudget)

-- | The budget that you want to update your budget to.
updateBudget_newBudget :: Lens.Lens' UpdateBudget Budget
updateBudget_newBudget :: Lens' UpdateBudget Budget
updateBudget_newBudget = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateBudget' {Budget
newBudget' :: Budget
$sel:newBudget':UpdateBudget' :: UpdateBudget -> Budget
newBudget'} -> Budget
newBudget') (\s :: UpdateBudget
s@UpdateBudget' {} Budget
a -> UpdateBudget
s {$sel:newBudget':UpdateBudget' :: Budget
newBudget' = Budget
a} :: UpdateBudget)

instance Core.AWSRequest UpdateBudget where
  type AWSResponse UpdateBudget = UpdateBudgetResponse
  request :: (Service -> Service) -> UpdateBudget -> Request UpdateBudget
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 UpdateBudget
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateBudget)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> UpdateBudgetResponse
UpdateBudgetResponse'
            forall (f :: * -> *) a b. Functor 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 UpdateBudget where
  hashWithSalt :: Int -> UpdateBudget -> Int
hashWithSalt Int
_salt UpdateBudget' {Text
Budget
newBudget' :: Budget
accountId :: Text
$sel:newBudget':UpdateBudget' :: UpdateBudget -> Budget
$sel:accountId:UpdateBudget' :: UpdateBudget -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
accountId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Budget
newBudget'

instance Prelude.NFData UpdateBudget where
  rnf :: UpdateBudget -> ()
rnf UpdateBudget' {Text
Budget
newBudget' :: Budget
accountId :: Text
$sel:newBudget':UpdateBudget' :: UpdateBudget -> Budget
$sel:accountId:UpdateBudget' :: UpdateBudget -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
accountId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Budget
newBudget'

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

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

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

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

-- |
-- Create a value of 'UpdateBudgetResponse' 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:
--
-- 'httpStatus', 'updateBudgetResponse_httpStatus' - The response's http status code.
newUpdateBudgetResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateBudgetResponse
newUpdateBudgetResponse :: Int -> UpdateBudgetResponse
newUpdateBudgetResponse Int
pHttpStatus_ =
  UpdateBudgetResponse' {$sel:httpStatus:UpdateBudgetResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
updateBudgetResponse_httpStatus :: Lens.Lens' UpdateBudgetResponse Prelude.Int
updateBudgetResponse_httpStatus :: Lens' UpdateBudgetResponse Int
updateBudgetResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateBudgetResponse' {Int
httpStatus :: Int
$sel:httpStatus:UpdateBudgetResponse' :: UpdateBudgetResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: UpdateBudgetResponse
s@UpdateBudgetResponse' {} Int
a -> UpdateBudgetResponse
s {$sel:httpStatus:UpdateBudgetResponse' :: Int
httpStatus = Int
a} :: UpdateBudgetResponse)

instance Prelude.NFData UpdateBudgetResponse where
  rnf :: UpdateBudgetResponse -> ()
rnf UpdateBudgetResponse' {Int
httpStatus :: Int
$sel:httpStatus:UpdateBudgetResponse' :: UpdateBudgetResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus