{-# 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.CreateNotification
-- 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 notification. You must create the budget before you create the
-- associated notification.
module Amazonka.Budgets.CreateNotification
  ( -- * Creating a Request
    CreateNotification (..),
    newCreateNotification,

    -- * Request Lenses
    createNotification_accountId,
    createNotification_budgetName,
    createNotification_notification,
    createNotification_subscribers,

    -- * Destructuring the Response
    CreateNotificationResponse (..),
    newCreateNotificationResponse,

    -- * Response Lenses
    createNotificationResponse_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 CreateNotification
--
-- /See:/ 'newCreateNotification' smart constructor.
data CreateNotification = CreateNotification'
  { -- | The @accountId@ that is associated with the budget that you want to
    -- create a notification for.
    CreateNotification -> Text
accountId :: Prelude.Text,
    -- | The name of the budget that you want Amazon Web Services to notify you
    -- about. Budget names must be unique within an account.
    CreateNotification -> Text
budgetName :: Prelude.Text,
    -- | The notification that you want to create.
    CreateNotification -> Notification
notification :: Notification,
    -- | A list of subscribers that you want to associate with the notification.
    -- Each notification can have one SNS subscriber and up to 10 email
    -- subscribers.
    CreateNotification -> NonEmpty Subscriber
subscribers :: Prelude.NonEmpty Subscriber
  }
  deriving (CreateNotification -> CreateNotification -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateNotification -> CreateNotification -> Bool
$c/= :: CreateNotification -> CreateNotification -> Bool
== :: CreateNotification -> CreateNotification -> Bool
$c== :: CreateNotification -> CreateNotification -> Bool
Prelude.Eq, Int -> CreateNotification -> ShowS
[CreateNotification] -> ShowS
CreateNotification -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateNotification] -> ShowS
$cshowList :: [CreateNotification] -> ShowS
show :: CreateNotification -> String
$cshow :: CreateNotification -> String
showsPrec :: Int -> CreateNotification -> ShowS
$cshowsPrec :: Int -> CreateNotification -> ShowS
Prelude.Show, forall x. Rep CreateNotification x -> CreateNotification
forall x. CreateNotification -> Rep CreateNotification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateNotification x -> CreateNotification
$cfrom :: forall x. CreateNotification -> Rep CreateNotification x
Prelude.Generic)

-- |
-- Create a value of 'CreateNotification' 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', 'createNotification_accountId' - The @accountId@ that is associated with the budget that you want to
-- create a notification for.
--
-- 'budgetName', 'createNotification_budgetName' - The name of the budget that you want Amazon Web Services to notify you
-- about. Budget names must be unique within an account.
--
-- 'notification', 'createNotification_notification' - The notification that you want to create.
--
-- 'subscribers', 'createNotification_subscribers' - A list of subscribers that you want to associate with the notification.
-- Each notification can have one SNS subscriber and up to 10 email
-- subscribers.
newCreateNotification ::
  -- | 'accountId'
  Prelude.Text ->
  -- | 'budgetName'
  Prelude.Text ->
  -- | 'notification'
  Notification ->
  -- | 'subscribers'
  Prelude.NonEmpty Subscriber ->
  CreateNotification
newCreateNotification :: Text
-> Text
-> Notification
-> NonEmpty Subscriber
-> CreateNotification
newCreateNotification
  Text
pAccountId_
  Text
pBudgetName_
  Notification
pNotification_
  NonEmpty Subscriber
pSubscribers_ =
    CreateNotification'
      { $sel:accountId:CreateNotification' :: Text
accountId = Text
pAccountId_,
        $sel:budgetName:CreateNotification' :: Text
budgetName = Text
pBudgetName_,
        $sel:notification:CreateNotification' :: Notification
notification = Notification
pNotification_,
        $sel:subscribers:CreateNotification' :: NonEmpty Subscriber
subscribers = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Subscriber
pSubscribers_
      }

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

-- | The name of the budget that you want Amazon Web Services to notify you
-- about. Budget names must be unique within an account.
createNotification_budgetName :: Lens.Lens' CreateNotification Prelude.Text
createNotification_budgetName :: Lens' CreateNotification Text
createNotification_budgetName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateNotification' {Text
budgetName :: Text
$sel:budgetName:CreateNotification' :: CreateNotification -> Text
budgetName} -> Text
budgetName) (\s :: CreateNotification
s@CreateNotification' {} Text
a -> CreateNotification
s {$sel:budgetName:CreateNotification' :: Text
budgetName = Text
a} :: CreateNotification)

-- | The notification that you want to create.
createNotification_notification :: Lens.Lens' CreateNotification Notification
createNotification_notification :: Lens' CreateNotification Notification
createNotification_notification = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateNotification' {Notification
notification :: Notification
$sel:notification:CreateNotification' :: CreateNotification -> Notification
notification} -> Notification
notification) (\s :: CreateNotification
s@CreateNotification' {} Notification
a -> CreateNotification
s {$sel:notification:CreateNotification' :: Notification
notification = Notification
a} :: CreateNotification)

-- | A list of subscribers that you want to associate with the notification.
-- Each notification can have one SNS subscriber and up to 10 email
-- subscribers.
createNotification_subscribers :: Lens.Lens' CreateNotification (Prelude.NonEmpty Subscriber)
createNotification_subscribers :: Lens' CreateNotification (NonEmpty Subscriber)
createNotification_subscribers = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateNotification' {NonEmpty Subscriber
subscribers :: NonEmpty Subscriber
$sel:subscribers:CreateNotification' :: CreateNotification -> NonEmpty Subscriber
subscribers} -> NonEmpty Subscriber
subscribers) (\s :: CreateNotification
s@CreateNotification' {} NonEmpty Subscriber
a -> CreateNotification
s {$sel:subscribers:CreateNotification' :: NonEmpty Subscriber
subscribers = NonEmpty Subscriber
a} :: CreateNotification) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest CreateNotification where
  type
    AWSResponse CreateNotification =
      CreateNotificationResponse
  request :: (Service -> Service)
-> CreateNotification -> Request CreateNotification
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 CreateNotification
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateNotification)))
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 -> CreateNotificationResponse
CreateNotificationResponse'
            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 CreateNotification where
  hashWithSalt :: Int -> CreateNotification -> Int
hashWithSalt Int
_salt CreateNotification' {NonEmpty Subscriber
Text
Notification
subscribers :: NonEmpty Subscriber
notification :: Notification
budgetName :: Text
accountId :: Text
$sel:subscribers:CreateNotification' :: CreateNotification -> NonEmpty Subscriber
$sel:notification:CreateNotification' :: CreateNotification -> Notification
$sel:budgetName:CreateNotification' :: CreateNotification -> Text
$sel:accountId:CreateNotification' :: CreateNotification -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
accountId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
budgetName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Notification
notification
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Subscriber
subscribers

instance Prelude.NFData CreateNotification where
  rnf :: CreateNotification -> ()
rnf CreateNotification' {NonEmpty Subscriber
Text
Notification
subscribers :: NonEmpty Subscriber
notification :: Notification
budgetName :: Text
accountId :: Text
$sel:subscribers:CreateNotification' :: CreateNotification -> NonEmpty Subscriber
$sel:notification:CreateNotification' :: CreateNotification -> Notification
$sel:budgetName:CreateNotification' :: CreateNotification -> Text
$sel:accountId:CreateNotification' :: CreateNotification -> 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 Text
budgetName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Notification
notification
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Subscriber
subscribers

instance Data.ToHeaders CreateNotification where
  toHeaders :: CreateNotification -> 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.CreateNotification" ::
                          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 CreateNotification where
  toJSON :: CreateNotification -> Value
toJSON CreateNotification' {NonEmpty Subscriber
Text
Notification
subscribers :: NonEmpty Subscriber
notification :: Notification
budgetName :: Text
accountId :: Text
$sel:subscribers:CreateNotification' :: CreateNotification -> NonEmpty Subscriber
$sel:notification:CreateNotification' :: CreateNotification -> Notification
$sel:budgetName:CreateNotification' :: CreateNotification -> Text
$sel:accountId:CreateNotification' :: CreateNotification -> 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
"BudgetName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
budgetName),
            forall a. a -> Maybe a
Prelude.Just (Key
"Notification" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Notification
notification),
            forall a. a -> Maybe a
Prelude.Just (Key
"Subscribers" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Subscriber
subscribers)
          ]
      )

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

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

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

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

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

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