{-# 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-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 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 AWS 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.Lens as Lens
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
(UpdateBudget -> UpdateBudget -> Bool)
-> (UpdateBudget -> UpdateBudget -> Bool) -> Eq UpdateBudget
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]
(Int -> ReadS UpdateBudget)
-> ReadS [UpdateBudget]
-> ReadPrec UpdateBudget
-> ReadPrec [UpdateBudget]
-> Read 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
(Int -> UpdateBudget -> ShowS)
-> (UpdateBudget -> String)
-> ([UpdateBudget] -> ShowS)
-> Show UpdateBudget
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. UpdateBudget -> Rep UpdateBudget x)
-> (forall x. Rep UpdateBudget x -> UpdateBudget)
-> Generic UpdateBudget
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' :: Text -> Budget -> UpdateBudget
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 :: (Text -> f Text) -> UpdateBudget -> f UpdateBudget
updateBudget_accountId = (UpdateBudget -> Text)
-> (UpdateBudget -> Text -> UpdateBudget)
-> Lens UpdateBudget UpdateBudget Text Text
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 :: (Budget -> f Budget) -> UpdateBudget -> f UpdateBudget
updateBudget_newBudget = (UpdateBudget -> Budget)
-> (UpdateBudget -> Budget -> UpdateBudget)
-> Lens UpdateBudget UpdateBudget Budget Budget
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 :: UpdateBudget -> Request UpdateBudget
request = Service -> UpdateBudget -> Request UpdateBudget
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateBudget
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateBudget)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdateBudget))
-> Logger
-> Service
-> Proxy UpdateBudget
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateBudget)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> UpdateBudgetResponse
UpdateBudgetResponse'
            (Int -> UpdateBudgetResponse)
-> Either String Int -> Either String UpdateBudgetResponse
forall (f :: * -> *) a b. Functor 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 UpdateBudget

instance Prelude.NFData UpdateBudget

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

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

instance Core.ToQuery UpdateBudget where
  toQuery :: UpdateBudget -> QueryString
toQuery = QueryString -> UpdateBudget -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(UpdateBudgetResponse -> UpdateBudgetResponse -> Bool)
-> (UpdateBudgetResponse -> UpdateBudgetResponse -> Bool)
-> Eq UpdateBudgetResponse
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]
(Int -> ReadS UpdateBudgetResponse)
-> ReadS [UpdateBudgetResponse]
-> ReadPrec UpdateBudgetResponse
-> ReadPrec [UpdateBudgetResponse]
-> Read 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
(Int -> UpdateBudgetResponse -> ShowS)
-> (UpdateBudgetResponse -> String)
-> ([UpdateBudgetResponse] -> ShowS)
-> Show UpdateBudgetResponse
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. UpdateBudgetResponse -> Rep UpdateBudgetResponse x)
-> (forall x. Rep UpdateBudgetResponse x -> UpdateBudgetResponse)
-> Generic UpdateBudgetResponse
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' :: Int -> UpdateBudgetResponse
UpdateBudgetResponse' {$sel:httpStatus:UpdateBudgetResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
updateBudgetResponse_httpStatus :: Lens.Lens' UpdateBudgetResponse Prelude.Int
updateBudgetResponse_httpStatus :: (Int -> f Int) -> UpdateBudgetResponse -> f UpdateBudgetResponse
updateBudgetResponse_httpStatus = (UpdateBudgetResponse -> Int)
-> (UpdateBudgetResponse -> Int -> UpdateBudgetResponse)
-> Lens UpdateBudgetResponse UpdateBudgetResponse Int Int
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