{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.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 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
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
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. 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'
      { $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 :: Lens' CreateSubscriber Text
createSubscriber_accountId = 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 :: Lens' CreateSubscriber Text
createSubscriber_budgetName = 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 :: Lens' CreateSubscriber Notification
createSubscriber_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 :: Lens' CreateSubscriber Subscriber
createSubscriber_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 :: (Service -> Service)
-> CreateSubscriber -> Request CreateSubscriber
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 CreateSubscriber
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateSubscriber)))
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 -> CreateSubscriberResponse
CreateSubscriberResponse'
            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 CreateSubscriber where
  hashWithSalt :: Int -> CreateSubscriber -> Int
hashWithSalt Int
_salt 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
..} =
    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` Subscriber
subscriber

instance Prelude.NFData CreateSubscriber where
  rnf :: CreateSubscriber -> ()
rnf 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
..} =
    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 Subscriber
subscriber

instance Data.ToHeaders CreateSubscriber where
  toHeaders :: CreateSubscriber -> 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.CreateSubscriber" ::
                          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 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
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
"Subscriber" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Subscriber
subscriber)
          ]
      )

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

instance Data.ToQuery CreateSubscriber where
  toQuery :: CreateSubscriber -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:httpStatus:CreateSubscriberResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
createSubscriberResponse_httpStatus :: Lens.Lens' CreateSubscriberResponse Prelude.Int
createSubscriberResponse_httpStatus :: Lens' CreateSubscriberResponse Int
createSubscriberResponse_httpStatus = 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 where
  rnf :: CreateSubscriberResponse -> ()
rnf CreateSubscriberResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateSubscriberResponse' :: CreateSubscriberResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus