{-# 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.CloudWatchEvents.CreateEventBus
-- 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 new event bus within your account. This can be a custom event
-- bus which you can use to receive events from your custom applications
-- and services, or it can be a partner event bus which can be matched to a
-- partner event source.
module Amazonka.CloudWatchEvents.CreateEventBus
  ( -- * Creating a Request
    CreateEventBus (..),
    newCreateEventBus,

    -- * Request Lenses
    createEventBus_eventSourceName,
    createEventBus_tags,
    createEventBus_name,

    -- * Destructuring the Response
    CreateEventBusResponse (..),
    newCreateEventBusResponse,

    -- * Response Lenses
    createEventBusResponse_eventBusArn,
    createEventBusResponse_httpStatus,
  )
where

import Amazonka.CloudWatchEvents.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

-- | /See:/ 'newCreateEventBus' smart constructor.
data CreateEventBus = CreateEventBus'
  { -- | If you are creating a partner event bus, this specifies the partner
    -- event source that the new event bus will be matched with.
    CreateEventBus -> Maybe Text
eventSourceName :: Prelude.Maybe Prelude.Text,
    -- | Tags to associate with the event bus.
    CreateEventBus -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The name of the new event bus.
    --
    -- Event bus names cannot contain the \/ character. You can\'t use the name
    -- @default@ for a custom event bus, as this name is already used for your
    -- account\'s default event bus.
    --
    -- If this is a partner event bus, the name must exactly match the name of
    -- the partner event source that this event bus is matched to.
    CreateEventBus -> Text
name :: Prelude.Text
  }
  deriving (CreateEventBus -> CreateEventBus -> Bool
(CreateEventBus -> CreateEventBus -> Bool)
-> (CreateEventBus -> CreateEventBus -> Bool) -> Eq CreateEventBus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateEventBus -> CreateEventBus -> Bool
$c/= :: CreateEventBus -> CreateEventBus -> Bool
== :: CreateEventBus -> CreateEventBus -> Bool
$c== :: CreateEventBus -> CreateEventBus -> Bool
Prelude.Eq, ReadPrec [CreateEventBus]
ReadPrec CreateEventBus
Int -> ReadS CreateEventBus
ReadS [CreateEventBus]
(Int -> ReadS CreateEventBus)
-> ReadS [CreateEventBus]
-> ReadPrec CreateEventBus
-> ReadPrec [CreateEventBus]
-> Read CreateEventBus
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateEventBus]
$creadListPrec :: ReadPrec [CreateEventBus]
readPrec :: ReadPrec CreateEventBus
$creadPrec :: ReadPrec CreateEventBus
readList :: ReadS [CreateEventBus]
$creadList :: ReadS [CreateEventBus]
readsPrec :: Int -> ReadS CreateEventBus
$creadsPrec :: Int -> ReadS CreateEventBus
Prelude.Read, Int -> CreateEventBus -> ShowS
[CreateEventBus] -> ShowS
CreateEventBus -> String
(Int -> CreateEventBus -> ShowS)
-> (CreateEventBus -> String)
-> ([CreateEventBus] -> ShowS)
-> Show CreateEventBus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateEventBus] -> ShowS
$cshowList :: [CreateEventBus] -> ShowS
show :: CreateEventBus -> String
$cshow :: CreateEventBus -> String
showsPrec :: Int -> CreateEventBus -> ShowS
$cshowsPrec :: Int -> CreateEventBus -> ShowS
Prelude.Show, (forall x. CreateEventBus -> Rep CreateEventBus x)
-> (forall x. Rep CreateEventBus x -> CreateEventBus)
-> Generic CreateEventBus
forall x. Rep CreateEventBus x -> CreateEventBus
forall x. CreateEventBus -> Rep CreateEventBus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateEventBus x -> CreateEventBus
$cfrom :: forall x. CreateEventBus -> Rep CreateEventBus x
Prelude.Generic)

-- |
-- Create a value of 'CreateEventBus' 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:
--
-- 'eventSourceName', 'createEventBus_eventSourceName' - If you are creating a partner event bus, this specifies the partner
-- event source that the new event bus will be matched with.
--
-- 'tags', 'createEventBus_tags' - Tags to associate with the event bus.
--
-- 'name', 'createEventBus_name' - The name of the new event bus.
--
-- Event bus names cannot contain the \/ character. You can\'t use the name
-- @default@ for a custom event bus, as this name is already used for your
-- account\'s default event bus.
--
-- If this is a partner event bus, the name must exactly match the name of
-- the partner event source that this event bus is matched to.
newCreateEventBus ::
  -- | 'name'
  Prelude.Text ->
  CreateEventBus
newCreateEventBus :: Text -> CreateEventBus
newCreateEventBus Text
pName_ =
  CreateEventBus' :: Maybe Text -> Maybe [Tag] -> Text -> CreateEventBus
CreateEventBus'
    { $sel:eventSourceName:CreateEventBus' :: Maybe Text
eventSourceName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateEventBus' :: Maybe [Tag]
tags = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing,
      $sel:name:CreateEventBus' :: Text
name = Text
pName_
    }

-- | If you are creating a partner event bus, this specifies the partner
-- event source that the new event bus will be matched with.
createEventBus_eventSourceName :: Lens.Lens' CreateEventBus (Prelude.Maybe Prelude.Text)
createEventBus_eventSourceName :: (Maybe Text -> f (Maybe Text))
-> CreateEventBus -> f CreateEventBus
createEventBus_eventSourceName = (CreateEventBus -> Maybe Text)
-> (CreateEventBus -> Maybe Text -> CreateEventBus)
-> Lens CreateEventBus CreateEventBus (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEventBus' {Maybe Text
eventSourceName :: Maybe Text
$sel:eventSourceName:CreateEventBus' :: CreateEventBus -> Maybe Text
eventSourceName} -> Maybe Text
eventSourceName) (\s :: CreateEventBus
s@CreateEventBus' {} Maybe Text
a -> CreateEventBus
s {$sel:eventSourceName:CreateEventBus' :: Maybe Text
eventSourceName = Maybe Text
a} :: CreateEventBus)

-- | Tags to associate with the event bus.
createEventBus_tags :: Lens.Lens' CreateEventBus (Prelude.Maybe [Tag])
createEventBus_tags :: (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateEventBus -> f CreateEventBus
createEventBus_tags = (CreateEventBus -> Maybe [Tag])
-> (CreateEventBus -> Maybe [Tag] -> CreateEventBus)
-> Lens CreateEventBus CreateEventBus (Maybe [Tag]) (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEventBus' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateEventBus' :: CreateEventBus -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateEventBus
s@CreateEventBus' {} Maybe [Tag]
a -> CreateEventBus
s {$sel:tags:CreateEventBus' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateEventBus) ((Maybe [Tag] -> f (Maybe [Tag]))
 -> CreateEventBus -> f CreateEventBus)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateEventBus
-> f CreateEventBus
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
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 [Tag] [Tag] [Tag] [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the new event bus.
--
-- Event bus names cannot contain the \/ character. You can\'t use the name
-- @default@ for a custom event bus, as this name is already used for your
-- account\'s default event bus.
--
-- If this is a partner event bus, the name must exactly match the name of
-- the partner event source that this event bus is matched to.
createEventBus_name :: Lens.Lens' CreateEventBus Prelude.Text
createEventBus_name :: (Text -> f Text) -> CreateEventBus -> f CreateEventBus
createEventBus_name = (CreateEventBus -> Text)
-> (CreateEventBus -> Text -> CreateEventBus)
-> Lens CreateEventBus CreateEventBus Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEventBus' {Text
name :: Text
$sel:name:CreateEventBus' :: CreateEventBus -> Text
name} -> Text
name) (\s :: CreateEventBus
s@CreateEventBus' {} Text
a -> CreateEventBus
s {$sel:name:CreateEventBus' :: Text
name = Text
a} :: CreateEventBus)

instance Core.AWSRequest CreateEventBus where
  type
    AWSResponse CreateEventBus =
      CreateEventBusResponse
  request :: CreateEventBus -> Request CreateEventBus
request = Service -> CreateEventBus -> Request CreateEventBus
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateEventBus
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateEventBus)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateEventBus))
-> Logger
-> Service
-> Proxy CreateEventBus
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateEventBus)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> CreateEventBusResponse
CreateEventBusResponse'
            (Maybe Text -> Int -> CreateEventBusResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CreateEventBusResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"EventBusArn")
            Either String (Int -> CreateEventBusResponse)
-> Either String Int -> Either String CreateEventBusResponse
forall (f :: * -> *) a b. Applicative f => 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 CreateEventBus

instance Prelude.NFData CreateEventBus

instance Core.ToHeaders CreateEventBus where
  toHeaders :: CreateEventBus -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateEventBus -> 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
"AWSEvents.CreateEventBus" :: 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 CreateEventBus where
  toJSON :: CreateEventBus -> Value
toJSON CreateEventBus' {Maybe [Tag]
Maybe Text
Text
name :: Text
tags :: Maybe [Tag]
eventSourceName :: Maybe Text
$sel:name:CreateEventBus' :: CreateEventBus -> Text
$sel:tags:CreateEventBus' :: CreateEventBus -> Maybe [Tag]
$sel:eventSourceName:CreateEventBus' :: CreateEventBus -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EventSourceName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
eventSourceName,
            (Text
"Tags" Text -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Tag] -> Pair) -> Maybe [Tag] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )

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

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

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

-- |
-- Create a value of 'CreateEventBusResponse' 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:
--
-- 'eventBusArn', 'createEventBusResponse_eventBusArn' - The ARN of the new event bus.
--
-- 'httpStatus', 'createEventBusResponse_httpStatus' - The response's http status code.
newCreateEventBusResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateEventBusResponse
newCreateEventBusResponse :: Int -> CreateEventBusResponse
newCreateEventBusResponse Int
pHttpStatus_ =
  CreateEventBusResponse' :: Maybe Text -> Int -> CreateEventBusResponse
CreateEventBusResponse'
    { $sel:eventBusArn:CreateEventBusResponse' :: Maybe Text
eventBusArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateEventBusResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the new event bus.
createEventBusResponse_eventBusArn :: Lens.Lens' CreateEventBusResponse (Prelude.Maybe Prelude.Text)
createEventBusResponse_eventBusArn :: (Maybe Text -> f (Maybe Text))
-> CreateEventBusResponse -> f CreateEventBusResponse
createEventBusResponse_eventBusArn = (CreateEventBusResponse -> Maybe Text)
-> (CreateEventBusResponse -> Maybe Text -> CreateEventBusResponse)
-> Lens
     CreateEventBusResponse
     CreateEventBusResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEventBusResponse' {Maybe Text
eventBusArn :: Maybe Text
$sel:eventBusArn:CreateEventBusResponse' :: CreateEventBusResponse -> Maybe Text
eventBusArn} -> Maybe Text
eventBusArn) (\s :: CreateEventBusResponse
s@CreateEventBusResponse' {} Maybe Text
a -> CreateEventBusResponse
s {$sel:eventBusArn:CreateEventBusResponse' :: Maybe Text
eventBusArn = Maybe Text
a} :: CreateEventBusResponse)

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

instance Prelude.NFData CreateEventBusResponse