{-# 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-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)
--
-- 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.Lens as Lens
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, AWS 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
(CreateBudget -> CreateBudget -> Bool)
-> (CreateBudget -> CreateBudget -> Bool) -> Eq CreateBudget
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
(Int -> CreateBudget -> ShowS)
-> (CreateBudget -> String)
-> ([CreateBudget] -> ShowS)
-> Show CreateBudget
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. CreateBudget -> Rep CreateBudget x)
-> (forall x. Rep CreateBudget x -> CreateBudget)
-> Generic CreateBudget
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, AWS 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' :: Maybe [NotificationWithSubscribers]
-> Text -> Budget -> CreateBudget
CreateBudget'
    { $sel:notificationsWithSubscribers:CreateBudget' :: Maybe [NotificationWithSubscribers]
notificationsWithSubscribers =
        Maybe [NotificationWithSubscribers]
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, AWS creates the
-- notifications and subscribers for you.
createBudget_notificationsWithSubscribers :: Lens.Lens' CreateBudget (Prelude.Maybe [NotificationWithSubscribers])
createBudget_notificationsWithSubscribers :: (Maybe [NotificationWithSubscribers]
 -> f (Maybe [NotificationWithSubscribers]))
-> CreateBudget -> f CreateBudget
createBudget_notificationsWithSubscribers = (CreateBudget -> Maybe [NotificationWithSubscribers])
-> (CreateBudget
    -> Maybe [NotificationWithSubscribers] -> CreateBudget)
-> Lens
     CreateBudget
     CreateBudget
     (Maybe [NotificationWithSubscribers])
     (Maybe [NotificationWithSubscribers])
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) ((Maybe [NotificationWithSubscribers]
  -> f (Maybe [NotificationWithSubscribers]))
 -> CreateBudget -> f CreateBudget)
-> ((Maybe [NotificationWithSubscribers]
     -> f (Maybe [NotificationWithSubscribers]))
    -> Maybe [NotificationWithSubscribers]
    -> f (Maybe [NotificationWithSubscribers]))
-> (Maybe [NotificationWithSubscribers]
    -> f (Maybe [NotificationWithSubscribers]))
-> CreateBudget
-> f CreateBudget
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [NotificationWithSubscribers]
  [NotificationWithSubscribers]
  [NotificationWithSubscribers]
  [NotificationWithSubscribers]
-> Iso
     (Maybe [NotificationWithSubscribers])
     (Maybe [NotificationWithSubscribers])
     (Maybe [NotificationWithSubscribers])
     (Maybe [NotificationWithSubscribers])
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
  [NotificationWithSubscribers]
  [NotificationWithSubscribers]
  [NotificationWithSubscribers]
  [NotificationWithSubscribers]
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 :: (Text -> f Text) -> CreateBudget -> f CreateBudget
createBudget_accountId = (CreateBudget -> Text)
-> (CreateBudget -> Text -> CreateBudget)
-> Lens CreateBudget CreateBudget Text Text
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 :: (Budget -> f Budget) -> CreateBudget -> f CreateBudget
createBudget_budget = (CreateBudget -> Budget)
-> (CreateBudget -> Budget -> CreateBudget)
-> Lens CreateBudget CreateBudget Budget 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 :: CreateBudget -> Request CreateBudget
request = Service -> CreateBudget -> Request CreateBudget
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateBudget
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateBudget)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreateBudget))
-> Logger
-> Service
-> Proxy CreateBudget
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateBudget)))
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 -> CreateBudgetResponse
CreateBudgetResponse'
            (Int -> CreateBudgetResponse)
-> Either String Int -> Either String CreateBudgetResponse
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 CreateBudget

instance Prelude.NFData CreateBudget

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

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

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

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