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

    -- * Request Lenses
    createSubscriber_accountId,
    createSubscriber_budgetName,
    createSubscriber_notification,
    createSubscriber_subscriber,

    -- * Destructuring the Response
    CreateSubscriberResponse (..),
    newCreateSubscriberResponse,

    -- * Response Lenses
    createSubscriberResponse_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 CreateSubscriber
--
-- /See:/ 'newCreateSubscriber' smart constructor.
data CreateSubscriber = CreateSubscriber'
  { -- | The @accountId@ that is associated with the budget that you want to
    -- create a subscriber for.
    CreateSubscriber -> Text
accountId :: Prelude.Text,
    -- | The name of the budget that you want to subscribe to. Budget names must
    -- be unique within an account.
    CreateSubscriber -> Text
budgetName :: Prelude.Text,
    -- | The notification that you want to create a subscriber for.
    CreateSubscriber -> Notification
notification :: Notification,
    -- | The subscriber that you want to associate with a budget notification.
    CreateSubscriber -> Subscriber
subscriber :: Subscriber
  }
  deriving (CreateSubscriber -> CreateSubscriber -> Bool
(CreateSubscriber -> CreateSubscriber -> Bool)
-> (CreateSubscriber -> CreateSubscriber -> Bool)
-> Eq CreateSubscriber
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateSubscriber -> CreateSubscriber -> Bool
$c/= :: CreateSubscriber -> CreateSubscriber -> Bool
== :: CreateSubscriber -> CreateSubscriber -> Bool
$c== :: CreateSubscriber -> CreateSubscriber -> Bool
Prelude.Eq, Int -> CreateSubscriber -> ShowS
[CreateSubscriber] -> ShowS
CreateSubscriber -> String
(Int -> CreateSubscriber -> ShowS)
-> (CreateSubscriber -> String)
-> ([CreateSubscriber] -> ShowS)
-> Show CreateSubscriber
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateSubscriber] -> ShowS
$cshowList :: [CreateSubscriber] -> ShowS
show :: CreateSubscriber -> String
$cshow :: CreateSubscriber -> String
showsPrec :: Int -> CreateSubscriber -> ShowS
$cshowsPrec :: Int -> CreateSubscriber -> ShowS
Prelude.Show, (forall x. CreateSubscriber -> Rep CreateSubscriber x)
-> (forall x. Rep CreateSubscriber x -> CreateSubscriber)
-> Generic CreateSubscriber
forall x. Rep CreateSubscriber x -> CreateSubscriber
forall x. CreateSubscriber -> Rep CreateSubscriber x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateSubscriber x -> CreateSubscriber
$cfrom :: forall x. CreateSubscriber -> Rep CreateSubscriber x
Prelude.Generic)

-- |
-- Create a value of 'CreateSubscriber' 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', 'createSubscriber_accountId' - The @accountId@ that is associated with the budget that you want to
-- create a subscriber for.
--
-- 'budgetName', 'createSubscriber_budgetName' - The name of the budget that you want to subscribe to. Budget names must
-- be unique within an account.
--
-- 'notification', 'createSubscriber_notification' - The notification that you want to create a subscriber for.
--
-- 'subscriber', 'createSubscriber_subscriber' - The subscriber that you want to associate with a budget notification.
newCreateSubscriber ::
  -- | 'accountId'
  Prelude.Text ->
  -- | 'budgetName'
  Prelude.Text ->
  -- | 'notification'
  Notification ->
  -- | 'subscriber'
  Subscriber ->
  CreateSubscriber
newCreateSubscriber :: Text -> Text -> Notification -> Subscriber -> CreateSubscriber
newCreateSubscriber
  Text
pAccountId_
  Text
pBudgetName_
  Notification
pNotification_
  Subscriber
pSubscriber_ =
    CreateSubscriber' :: Text -> Text -> Notification -> Subscriber -> CreateSubscriber
CreateSubscriber'
      { $sel:accountId:CreateSubscriber' :: Text
accountId = Text
pAccountId_,
        $sel:budgetName:CreateSubscriber' :: Text
budgetName = Text
pBudgetName_,
        $sel:notification:CreateSubscriber' :: Notification
notification = Notification
pNotification_,
        $sel:subscriber:CreateSubscriber' :: Subscriber
subscriber = Subscriber
pSubscriber_
      }

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

-- | The name of the budget that you want to subscribe to. Budget names must
-- be unique within an account.
createSubscriber_budgetName :: Lens.Lens' CreateSubscriber Prelude.Text
createSubscriber_budgetName :: (Text -> f Text) -> CreateSubscriber -> f CreateSubscriber
createSubscriber_budgetName = (CreateSubscriber -> Text)
-> (CreateSubscriber -> Text -> CreateSubscriber)
-> Lens CreateSubscriber CreateSubscriber Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSubscriber' {Text
budgetName :: Text
$sel:budgetName:CreateSubscriber' :: CreateSubscriber -> Text
budgetName} -> Text
budgetName) (\s :: CreateSubscriber
s@CreateSubscriber' {} Text
a -> CreateSubscriber
s {$sel:budgetName:CreateSubscriber' :: Text
budgetName = Text
a} :: CreateSubscriber)

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

-- | The subscriber that you want to associate with a budget notification.
createSubscriber_subscriber :: Lens.Lens' CreateSubscriber Subscriber
createSubscriber_subscriber :: (Subscriber -> f Subscriber)
-> CreateSubscriber -> f CreateSubscriber
createSubscriber_subscriber = (CreateSubscriber -> Subscriber)
-> (CreateSubscriber -> Subscriber -> CreateSubscriber)
-> Lens CreateSubscriber CreateSubscriber Subscriber Subscriber
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSubscriber' {Subscriber
subscriber :: Subscriber
$sel:subscriber:CreateSubscriber' :: CreateSubscriber -> Subscriber
subscriber} -> Subscriber
subscriber) (\s :: CreateSubscriber
s@CreateSubscriber' {} Subscriber
a -> CreateSubscriber
s {$sel:subscriber:CreateSubscriber' :: Subscriber
subscriber = Subscriber
a} :: CreateSubscriber)

instance Core.AWSRequest CreateSubscriber where
  type
    AWSResponse CreateSubscriber =
      CreateSubscriberResponse
  request :: CreateSubscriber -> Request CreateSubscriber
request = Service -> CreateSubscriber -> Request CreateSubscriber
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateSubscriber
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateSubscriber)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreateSubscriber))
-> Logger
-> Service
-> Proxy CreateSubscriber
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateSubscriber)))
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 -> CreateSubscriberResponse
CreateSubscriberResponse'
            (Int -> CreateSubscriberResponse)
-> Either String Int -> Either String CreateSubscriberResponse
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 CreateSubscriber

instance Prelude.NFData CreateSubscriber

instance Core.ToHeaders CreateSubscriber where
  toHeaders :: CreateSubscriber -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateSubscriber -> 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.CreateSubscriber" ::
                          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 CreateSubscriber where
  toJSON :: CreateSubscriber -> Value
toJSON CreateSubscriber' {Text
Subscriber
Notification
subscriber :: Subscriber
notification :: Notification
budgetName :: Text
accountId :: Text
$sel:subscriber:CreateSubscriber' :: CreateSubscriber -> Subscriber
$sel:notification:CreateSubscriber' :: CreateSubscriber -> Notification
$sel:budgetName:CreateSubscriber' :: CreateSubscriber -> Text
$sel:accountId:CreateSubscriber' :: CreateSubscriber -> 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
"Subscriber" Text -> Subscriber -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Subscriber
subscriber)
          ]
      )

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

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

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

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

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

instance Prelude.NFData CreateSubscriberResponse