{-# 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.CreateBudget
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a budget and, if included, notifications and subscribers.
--
-- 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_CreateBudget.html#API_CreateBudget_Examples Examples>
-- section.
module Amazonka.Budgets.CreateBudget
  ( -- * Creating a Request
    CreateBudget (..),
    newCreateBudget,

    -- * Request Lenses
    createBudget_notificationsWithSubscribers,
    createBudget_accountId,
    createBudget_budget,

    -- * Destructuring the Response
    CreateBudgetResponse (..),
    newCreateBudgetResponse,

    -- * Response Lenses
    createBudgetResponse_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 CreateBudget
--
-- /See:/ 'newCreateBudget' smart constructor.
data CreateBudget = CreateBudget'
  { -- | A notification that you want to associate with a budget. A budget can
    -- have up to five notifications, and each notification can have one SNS
    -- subscriber and up to 10 email subscribers. If you include notifications
    -- and subscribers in your @CreateBudget@ call, Amazon Web Services creates
    -- the notifications and subscribers for you.
    CreateBudget -> Maybe [NotificationWithSubscribers]
notificationsWithSubscribers :: Prelude.Maybe [NotificationWithSubscribers],
    -- | The @accountId@ that is associated with the budget.
    CreateBudget -> Text
accountId :: Prelude.Text,
    -- | The budget object that you want to create.
    CreateBudget -> Budget
budget :: Budget
  }
  deriving (CreateBudget -> CreateBudget -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateBudget -> CreateBudget -> Bool
$c/= :: CreateBudget -> CreateBudget -> Bool
== :: CreateBudget -> CreateBudget -> Bool
$c== :: CreateBudget -> CreateBudget -> Bool
Prelude.Eq, Int -> CreateBudget -> ShowS
[CreateBudget] -> ShowS
CreateBudget -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateBudget] -> ShowS
$cshowList :: [CreateBudget] -> ShowS
show :: CreateBudget -> String
$cshow :: CreateBudget -> String
showsPrec :: Int -> CreateBudget -> ShowS
$cshowsPrec :: Int -> CreateBudget -> ShowS
Prelude.Show, forall x. Rep CreateBudget x -> CreateBudget
forall x. CreateBudget -> Rep CreateBudget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateBudget x -> CreateBudget
$cfrom :: forall x. CreateBudget -> Rep CreateBudget x
Prelude.Generic)

-- |
-- Create a value of 'CreateBudget' 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:
--
-- 'notificationsWithSubscribers', 'createBudget_notificationsWithSubscribers' - A notification that you want to associate with a budget. A budget can
-- have up to five notifications, and each notification can have one SNS
-- subscriber and up to 10 email subscribers. If you include notifications
-- and subscribers in your @CreateBudget@ call, Amazon Web Services creates
-- the notifications and subscribers for you.
--
-- 'accountId', 'createBudget_accountId' - The @accountId@ that is associated with the budget.
--
-- 'budget', 'createBudget_budget' - The budget object that you want to create.
newCreateBudget ::
  -- | 'accountId'
  Prelude.Text ->
  -- | 'budget'
  Budget ->
  CreateBudget
newCreateBudget :: Text -> Budget -> CreateBudget
newCreateBudget Text
pAccountId_ Budget
pBudget_ =
  CreateBudget'
    { $sel:notificationsWithSubscribers:CreateBudget' :: Maybe [NotificationWithSubscribers]
notificationsWithSubscribers =
        forall a. Maybe a
Prelude.Nothing,
      $sel:accountId:CreateBudget' :: Text
accountId = Text
pAccountId_,
      $sel:budget:CreateBudget' :: Budget
budget = Budget
pBudget_
    }

-- | A notification that you want to associate with a budget. A budget can
-- have up to five notifications, and each notification can have one SNS
-- subscriber and up to 10 email subscribers. If you include notifications
-- and subscribers in your @CreateBudget@ call, Amazon Web Services creates
-- the notifications and subscribers for you.
createBudget_notificationsWithSubscribers :: Lens.Lens' CreateBudget (Prelude.Maybe [NotificationWithSubscribers])
createBudget_notificationsWithSubscribers :: Lens' CreateBudget (Maybe [NotificationWithSubscribers])
createBudget_notificationsWithSubscribers = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBudget' {Maybe [NotificationWithSubscribers]
notificationsWithSubscribers :: Maybe [NotificationWithSubscribers]
$sel:notificationsWithSubscribers:CreateBudget' :: CreateBudget -> Maybe [NotificationWithSubscribers]
notificationsWithSubscribers} -> Maybe [NotificationWithSubscribers]
notificationsWithSubscribers) (\s :: CreateBudget
s@CreateBudget' {} Maybe [NotificationWithSubscribers]
a -> CreateBudget
s {$sel:notificationsWithSubscribers:CreateBudget' :: Maybe [NotificationWithSubscribers]
notificationsWithSubscribers = Maybe [NotificationWithSubscribers]
a} :: CreateBudget) 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 @accountId@ that is associated with the budget.
createBudget_accountId :: Lens.Lens' CreateBudget Prelude.Text
createBudget_accountId :: Lens' CreateBudget Text
createBudget_accountId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBudget' {Text
accountId :: Text
$sel:accountId:CreateBudget' :: CreateBudget -> Text
accountId} -> Text
accountId) (\s :: CreateBudget
s@CreateBudget' {} Text
a -> CreateBudget
s {$sel:accountId:CreateBudget' :: Text
accountId = Text
a} :: CreateBudget)

-- | The budget object that you want to create.
createBudget_budget :: Lens.Lens' CreateBudget Budget
createBudget_budget :: Lens' CreateBudget Budget
createBudget_budget = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBudget' {Budget
budget :: Budget
$sel:budget:CreateBudget' :: CreateBudget -> Budget
budget} -> Budget
budget) (\s :: CreateBudget
s@CreateBudget' {} Budget
a -> CreateBudget
s {$sel:budget:CreateBudget' :: Budget
budget = Budget
a} :: CreateBudget)

instance Core.AWSRequest CreateBudget where
  type AWSResponse CreateBudget = CreateBudgetResponse
  request :: (Service -> Service) -> CreateBudget -> Request CreateBudget
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 CreateBudget
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateBudget)))
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 -> CreateBudgetResponse
CreateBudgetResponse'
            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 CreateBudget where
  hashWithSalt :: Int -> CreateBudget -> Int
hashWithSalt Int
_salt CreateBudget' {Maybe [NotificationWithSubscribers]
Text
Budget
budget :: Budget
accountId :: Text
notificationsWithSubscribers :: Maybe [NotificationWithSubscribers]
$sel:budget:CreateBudget' :: CreateBudget -> Budget
$sel:accountId:CreateBudget' :: CreateBudget -> Text
$sel:notificationsWithSubscribers:CreateBudget' :: CreateBudget -> Maybe [NotificationWithSubscribers]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [NotificationWithSubscribers]
notificationsWithSubscribers
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
accountId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Budget
budget

instance Prelude.NFData CreateBudget where
  rnf :: CreateBudget -> ()
rnf CreateBudget' {Maybe [NotificationWithSubscribers]
Text
Budget
budget :: Budget
accountId :: Text
notificationsWithSubscribers :: Maybe [NotificationWithSubscribers]
$sel:budget:CreateBudget' :: CreateBudget -> Budget
$sel:accountId:CreateBudget' :: CreateBudget -> Text
$sel:notificationsWithSubscribers:CreateBudget' :: CreateBudget -> Maybe [NotificationWithSubscribers]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [NotificationWithSubscribers]
notificationsWithSubscribers
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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
budget

instance Data.ToHeaders CreateBudget where
  toHeaders :: CreateBudget -> 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.CreateBudget" ::
                          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 CreateBudget where
  toJSON :: CreateBudget -> Value
toJSON CreateBudget' {Maybe [NotificationWithSubscribers]
Text
Budget
budget :: Budget
accountId :: Text
notificationsWithSubscribers :: Maybe [NotificationWithSubscribers]
$sel:budget:CreateBudget' :: CreateBudget -> Budget
$sel:accountId:CreateBudget' :: CreateBudget -> Text
$sel:notificationsWithSubscribers:CreateBudget' :: CreateBudget -> Maybe [NotificationWithSubscribers]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"NotificationsWithSubscribers" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [NotificationWithSubscribers]
notificationsWithSubscribers,
            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
"Budget" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Budget
budget)
          ]
      )

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

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

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

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

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

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