{-# 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-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 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.Lens as Lens
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 AWS 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
(CreateNotification -> CreateNotification -> Bool)
-> (CreateNotification -> CreateNotification -> Bool)
-> Eq CreateNotification
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
(Int -> CreateNotification -> ShowS)
-> (CreateNotification -> String)
-> ([CreateNotification] -> ShowS)
-> Show CreateNotification
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. CreateNotification -> Rep CreateNotification x)
-> (forall x. Rep CreateNotification x -> CreateNotification)
-> Generic CreateNotification
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 AWS 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' :: Text
-> Text
-> Notification
-> NonEmpty Subscriber
-> CreateNotification
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 = Tagged (NonEmpty Subscriber) (Identity (NonEmpty Subscriber))
-> Tagged (NonEmpty Subscriber) (Identity (NonEmpty Subscriber))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Subscriber) (Identity (NonEmpty Subscriber))
 -> Tagged (NonEmpty Subscriber) (Identity (NonEmpty Subscriber)))
-> NonEmpty Subscriber -> NonEmpty Subscriber
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 :: (Text -> f Text) -> CreateNotification -> f CreateNotification
createNotification_accountId = (CreateNotification -> Text)
-> (CreateNotification -> Text -> CreateNotification)
-> Lens CreateNotification CreateNotification Text Text
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 AWS to notify you about. Budget
-- names must be unique within an account.
createNotification_budgetName :: Lens.Lens' CreateNotification Prelude.Text
createNotification_budgetName :: (Text -> f Text) -> CreateNotification -> f CreateNotification
createNotification_budgetName = (CreateNotification -> Text)
-> (CreateNotification -> Text -> CreateNotification)
-> Lens CreateNotification CreateNotification Text Text
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 :: (Notification -> f Notification)
-> CreateNotification -> f CreateNotification
createNotification_notification = (CreateNotification -> Notification)
-> (CreateNotification -> Notification -> CreateNotification)
-> Lens
     CreateNotification CreateNotification Notification 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 :: (NonEmpty Subscriber -> f (NonEmpty Subscriber))
-> CreateNotification -> f CreateNotification
createNotification_subscribers = (CreateNotification -> NonEmpty Subscriber)
-> (CreateNotification
    -> NonEmpty Subscriber -> CreateNotification)
-> Lens
     CreateNotification
     CreateNotification
     (NonEmpty Subscriber)
     (NonEmpty Subscriber)
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) ((NonEmpty Subscriber -> f (NonEmpty Subscriber))
 -> CreateNotification -> f CreateNotification)
-> ((NonEmpty Subscriber -> f (NonEmpty Subscriber))
    -> NonEmpty Subscriber -> f (NonEmpty Subscriber))
-> (NonEmpty Subscriber -> f (NonEmpty Subscriber))
-> CreateNotification
-> f CreateNotification
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Subscriber -> f (NonEmpty Subscriber))
-> NonEmpty Subscriber -> f (NonEmpty Subscriber)
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 :: CreateNotification -> Request CreateNotification
request = Service -> CreateNotification -> Request CreateNotification
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateNotification
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateNotification)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreateNotification))
-> Logger
-> Service
-> Proxy CreateNotification
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateNotification)))
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 -> CreateNotificationResponse
CreateNotificationResponse'
            (Int -> CreateNotificationResponse)
-> Either String Int -> Either String CreateNotificationResponse
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 CreateNotification

instance Prelude.NFData CreateNotification

instance Core.ToHeaders CreateNotification where
  toHeaders :: CreateNotification -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateNotification -> 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.CreateNotification" ::
                          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 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
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
"BudgetName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
budgetName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Notification" Text -> Notification -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Notification
notification),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Subscribers" Text -> NonEmpty Subscriber -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Subscriber
subscribers)
          ]
      )

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

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

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