{-# 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.CreatePartnerEventSource
-- 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)
--
-- Called by an SaaS partner to create a partner event source. This
-- operation is not used by Amazon Web Services customers.
--
-- Each partner event source can be used by one Amazon Web Services account
-- to create a matching partner event bus in that Amazon Web Services
-- account. A SaaS partner must create one partner event source for each
-- Amazon Web Services account that wants to receive those event types.
--
-- A partner event source creates events based on resources within the SaaS
-- partner\'s service or application.
--
-- An Amazon Web Services account that creates a partner event bus that
-- matches the partner event source can use that event bus to receive
-- events from the partner, and then process them using Amazon Web Services
-- Events rules and targets.
--
-- Partner event source names follow this format:
--
-- @ partner_name\/event_namespace\/event_name @
--
-- /partner_name/ is determined during partner registration and identifies
-- the partner to Amazon Web Services customers. /event_namespace/ is
-- determined by the partner and is a way for the partner to categorize
-- their events. /event_name/ is determined by the partner, and should
-- uniquely identify an event-generating resource within the partner
-- system. The combination of /event_namespace/ and /event_name/ should
-- help Amazon Web Services customers decide whether to create an event bus
-- to receive these events.
module Amazonka.CloudWatchEvents.CreatePartnerEventSource
  ( -- * Creating a Request
    CreatePartnerEventSource (..),
    newCreatePartnerEventSource,

    -- * Request Lenses
    createPartnerEventSource_name,
    createPartnerEventSource_account,

    -- * Destructuring the Response
    CreatePartnerEventSourceResponse (..),
    newCreatePartnerEventSourceResponse,

    -- * Response Lenses
    createPartnerEventSourceResponse_eventSourceArn,
    createPartnerEventSourceResponse_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:/ 'newCreatePartnerEventSource' smart constructor.
data CreatePartnerEventSource = CreatePartnerEventSource'
  { -- | The name of the partner event source. This name must be unique and must
    -- be in the format @ partner_name\/event_namespace\/event_name @. The
    -- Amazon Web Services account that wants to use this partner event source
    -- must create a partner event bus with a name that matches the name of the
    -- partner event source.
    CreatePartnerEventSource -> Text
name :: Prelude.Text,
    -- | The Amazon Web Services account ID that is permitted to create a
    -- matching partner event bus for this partner event source.
    CreatePartnerEventSource -> Text
account :: Prelude.Text
  }
  deriving (CreatePartnerEventSource -> CreatePartnerEventSource -> Bool
(CreatePartnerEventSource -> CreatePartnerEventSource -> Bool)
-> (CreatePartnerEventSource -> CreatePartnerEventSource -> Bool)
-> Eq CreatePartnerEventSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreatePartnerEventSource -> CreatePartnerEventSource -> Bool
$c/= :: CreatePartnerEventSource -> CreatePartnerEventSource -> Bool
== :: CreatePartnerEventSource -> CreatePartnerEventSource -> Bool
$c== :: CreatePartnerEventSource -> CreatePartnerEventSource -> Bool
Prelude.Eq, ReadPrec [CreatePartnerEventSource]
ReadPrec CreatePartnerEventSource
Int -> ReadS CreatePartnerEventSource
ReadS [CreatePartnerEventSource]
(Int -> ReadS CreatePartnerEventSource)
-> ReadS [CreatePartnerEventSource]
-> ReadPrec CreatePartnerEventSource
-> ReadPrec [CreatePartnerEventSource]
-> Read CreatePartnerEventSource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreatePartnerEventSource]
$creadListPrec :: ReadPrec [CreatePartnerEventSource]
readPrec :: ReadPrec CreatePartnerEventSource
$creadPrec :: ReadPrec CreatePartnerEventSource
readList :: ReadS [CreatePartnerEventSource]
$creadList :: ReadS [CreatePartnerEventSource]
readsPrec :: Int -> ReadS CreatePartnerEventSource
$creadsPrec :: Int -> ReadS CreatePartnerEventSource
Prelude.Read, Int -> CreatePartnerEventSource -> ShowS
[CreatePartnerEventSource] -> ShowS
CreatePartnerEventSource -> String
(Int -> CreatePartnerEventSource -> ShowS)
-> (CreatePartnerEventSource -> String)
-> ([CreatePartnerEventSource] -> ShowS)
-> Show CreatePartnerEventSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreatePartnerEventSource] -> ShowS
$cshowList :: [CreatePartnerEventSource] -> ShowS
show :: CreatePartnerEventSource -> String
$cshow :: CreatePartnerEventSource -> String
showsPrec :: Int -> CreatePartnerEventSource -> ShowS
$cshowsPrec :: Int -> CreatePartnerEventSource -> ShowS
Prelude.Show, (forall x.
 CreatePartnerEventSource -> Rep CreatePartnerEventSource x)
-> (forall x.
    Rep CreatePartnerEventSource x -> CreatePartnerEventSource)
-> Generic CreatePartnerEventSource
forall x.
Rep CreatePartnerEventSource x -> CreatePartnerEventSource
forall x.
CreatePartnerEventSource -> Rep CreatePartnerEventSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreatePartnerEventSource x -> CreatePartnerEventSource
$cfrom :: forall x.
CreatePartnerEventSource -> Rep CreatePartnerEventSource x
Prelude.Generic)

-- |
-- Create a value of 'CreatePartnerEventSource' 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:
--
-- 'name', 'createPartnerEventSource_name' - The name of the partner event source. This name must be unique and must
-- be in the format @ partner_name\/event_namespace\/event_name @. The
-- Amazon Web Services account that wants to use this partner event source
-- must create a partner event bus with a name that matches the name of the
-- partner event source.
--
-- 'account', 'createPartnerEventSource_account' - The Amazon Web Services account ID that is permitted to create a
-- matching partner event bus for this partner event source.
newCreatePartnerEventSource ::
  -- | 'name'
  Prelude.Text ->
  -- | 'account'
  Prelude.Text ->
  CreatePartnerEventSource
newCreatePartnerEventSource :: Text -> Text -> CreatePartnerEventSource
newCreatePartnerEventSource Text
pName_ Text
pAccount_ =
  CreatePartnerEventSource' :: Text -> Text -> CreatePartnerEventSource
CreatePartnerEventSource'
    { $sel:name:CreatePartnerEventSource' :: Text
name = Text
pName_,
      $sel:account:CreatePartnerEventSource' :: Text
account = Text
pAccount_
    }

-- | The name of the partner event source. This name must be unique and must
-- be in the format @ partner_name\/event_namespace\/event_name @. The
-- Amazon Web Services account that wants to use this partner event source
-- must create a partner event bus with a name that matches the name of the
-- partner event source.
createPartnerEventSource_name :: Lens.Lens' CreatePartnerEventSource Prelude.Text
createPartnerEventSource_name :: (Text -> f Text)
-> CreatePartnerEventSource -> f CreatePartnerEventSource
createPartnerEventSource_name = (CreatePartnerEventSource -> Text)
-> (CreatePartnerEventSource -> Text -> CreatePartnerEventSource)
-> Lens CreatePartnerEventSource CreatePartnerEventSource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePartnerEventSource' {Text
name :: Text
$sel:name:CreatePartnerEventSource' :: CreatePartnerEventSource -> Text
name} -> Text
name) (\s :: CreatePartnerEventSource
s@CreatePartnerEventSource' {} Text
a -> CreatePartnerEventSource
s {$sel:name:CreatePartnerEventSource' :: Text
name = Text
a} :: CreatePartnerEventSource)

-- | The Amazon Web Services account ID that is permitted to create a
-- matching partner event bus for this partner event source.
createPartnerEventSource_account :: Lens.Lens' CreatePartnerEventSource Prelude.Text
createPartnerEventSource_account :: (Text -> f Text)
-> CreatePartnerEventSource -> f CreatePartnerEventSource
createPartnerEventSource_account = (CreatePartnerEventSource -> Text)
-> (CreatePartnerEventSource -> Text -> CreatePartnerEventSource)
-> Lens CreatePartnerEventSource CreatePartnerEventSource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePartnerEventSource' {Text
account :: Text
$sel:account:CreatePartnerEventSource' :: CreatePartnerEventSource -> Text
account} -> Text
account) (\s :: CreatePartnerEventSource
s@CreatePartnerEventSource' {} Text
a -> CreatePartnerEventSource
s {$sel:account:CreatePartnerEventSource' :: Text
account = Text
a} :: CreatePartnerEventSource)

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

instance Prelude.NFData CreatePartnerEventSource

instance Core.ToHeaders CreatePartnerEventSource where
  toHeaders :: CreatePartnerEventSource -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreatePartnerEventSource -> 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.CreatePartnerEventSource" ::
                          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 CreatePartnerEventSource where
  toJSON :: CreatePartnerEventSource -> Value
toJSON CreatePartnerEventSource' {Text
account :: Text
name :: Text
$sel:account:CreatePartnerEventSource' :: CreatePartnerEventSource -> Text
$sel:name:CreatePartnerEventSource' :: CreatePartnerEventSource -> 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
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Account" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
account)
          ]
      )

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

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

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

-- |
-- Create a value of 'CreatePartnerEventSourceResponse' 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:
--
-- 'eventSourceArn', 'createPartnerEventSourceResponse_eventSourceArn' - The ARN of the partner event source.
--
-- 'httpStatus', 'createPartnerEventSourceResponse_httpStatus' - The response's http status code.
newCreatePartnerEventSourceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreatePartnerEventSourceResponse
newCreatePartnerEventSourceResponse :: Int -> CreatePartnerEventSourceResponse
newCreatePartnerEventSourceResponse Int
pHttpStatus_ =
  CreatePartnerEventSourceResponse' :: Maybe Text -> Int -> CreatePartnerEventSourceResponse
CreatePartnerEventSourceResponse'
    { $sel:eventSourceArn:CreatePartnerEventSourceResponse' :: Maybe Text
eventSourceArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreatePartnerEventSourceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the partner event source.
createPartnerEventSourceResponse_eventSourceArn :: Lens.Lens' CreatePartnerEventSourceResponse (Prelude.Maybe Prelude.Text)
createPartnerEventSourceResponse_eventSourceArn :: (Maybe Text -> f (Maybe Text))
-> CreatePartnerEventSourceResponse
-> f CreatePartnerEventSourceResponse
createPartnerEventSourceResponse_eventSourceArn = (CreatePartnerEventSourceResponse -> Maybe Text)
-> (CreatePartnerEventSourceResponse
    -> Maybe Text -> CreatePartnerEventSourceResponse)
-> Lens
     CreatePartnerEventSourceResponse
     CreatePartnerEventSourceResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePartnerEventSourceResponse' {Maybe Text
eventSourceArn :: Maybe Text
$sel:eventSourceArn:CreatePartnerEventSourceResponse' :: CreatePartnerEventSourceResponse -> Maybe Text
eventSourceArn} -> Maybe Text
eventSourceArn) (\s :: CreatePartnerEventSourceResponse
s@CreatePartnerEventSourceResponse' {} Maybe Text
a -> CreatePartnerEventSourceResponse
s {$sel:eventSourceArn:CreatePartnerEventSourceResponse' :: Maybe Text
eventSourceArn = Maybe Text
a} :: CreatePartnerEventSourceResponse)

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

instance
  Prelude.NFData
    CreatePartnerEventSourceResponse