{-# 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.PutPartnerEvents
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- This is used by SaaS partners to write events to a customer\'s partner
-- event bus. Amazon Web Services customers do not use this operation.
module Amazonka.CloudWatchEvents.PutPartnerEvents
  ( -- * Creating a Request
    PutPartnerEvents (..),
    newPutPartnerEvents,

    -- * Request Lenses
    putPartnerEvents_entries,

    -- * Destructuring the Response
    PutPartnerEventsResponse (..),
    newPutPartnerEventsResponse,

    -- * Response Lenses
    putPartnerEventsResponse_entries,
    putPartnerEventsResponse_failedEntryCount,
    putPartnerEventsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newPutPartnerEvents' smart constructor.
data PutPartnerEvents = PutPartnerEvents'
  { -- | The list of events to write to the event bus.
    PutPartnerEvents -> NonEmpty PutPartnerEventsRequestEntry
entries :: Prelude.NonEmpty PutPartnerEventsRequestEntry
  }
  deriving (PutPartnerEvents -> PutPartnerEvents -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutPartnerEvents -> PutPartnerEvents -> Bool
$c/= :: PutPartnerEvents -> PutPartnerEvents -> Bool
== :: PutPartnerEvents -> PutPartnerEvents -> Bool
$c== :: PutPartnerEvents -> PutPartnerEvents -> Bool
Prelude.Eq, ReadPrec [PutPartnerEvents]
ReadPrec PutPartnerEvents
Int -> ReadS PutPartnerEvents
ReadS [PutPartnerEvents]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutPartnerEvents]
$creadListPrec :: ReadPrec [PutPartnerEvents]
readPrec :: ReadPrec PutPartnerEvents
$creadPrec :: ReadPrec PutPartnerEvents
readList :: ReadS [PutPartnerEvents]
$creadList :: ReadS [PutPartnerEvents]
readsPrec :: Int -> ReadS PutPartnerEvents
$creadsPrec :: Int -> ReadS PutPartnerEvents
Prelude.Read, Int -> PutPartnerEvents -> ShowS
[PutPartnerEvents] -> ShowS
PutPartnerEvents -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutPartnerEvents] -> ShowS
$cshowList :: [PutPartnerEvents] -> ShowS
show :: PutPartnerEvents -> String
$cshow :: PutPartnerEvents -> String
showsPrec :: Int -> PutPartnerEvents -> ShowS
$cshowsPrec :: Int -> PutPartnerEvents -> ShowS
Prelude.Show, forall x. Rep PutPartnerEvents x -> PutPartnerEvents
forall x. PutPartnerEvents -> Rep PutPartnerEvents x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutPartnerEvents x -> PutPartnerEvents
$cfrom :: forall x. PutPartnerEvents -> Rep PutPartnerEvents x
Prelude.Generic)

-- |
-- Create a value of 'PutPartnerEvents' 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:
--
-- 'entries', 'putPartnerEvents_entries' - The list of events to write to the event bus.
newPutPartnerEvents ::
  -- | 'entries'
  Prelude.NonEmpty PutPartnerEventsRequestEntry ->
  PutPartnerEvents
newPutPartnerEvents :: NonEmpty PutPartnerEventsRequestEntry -> PutPartnerEvents
newPutPartnerEvents NonEmpty PutPartnerEventsRequestEntry
pEntries_ =
  PutPartnerEvents'
    { $sel:entries:PutPartnerEvents' :: NonEmpty PutPartnerEventsRequestEntry
entries =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty PutPartnerEventsRequestEntry
pEntries_
    }

-- | The list of events to write to the event bus.
putPartnerEvents_entries :: Lens.Lens' PutPartnerEvents (Prelude.NonEmpty PutPartnerEventsRequestEntry)
putPartnerEvents_entries :: Lens' PutPartnerEvents (NonEmpty PutPartnerEventsRequestEntry)
putPartnerEvents_entries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutPartnerEvents' {NonEmpty PutPartnerEventsRequestEntry
entries :: NonEmpty PutPartnerEventsRequestEntry
$sel:entries:PutPartnerEvents' :: PutPartnerEvents -> NonEmpty PutPartnerEventsRequestEntry
entries} -> NonEmpty PutPartnerEventsRequestEntry
entries) (\s :: PutPartnerEvents
s@PutPartnerEvents' {} NonEmpty PutPartnerEventsRequestEntry
a -> PutPartnerEvents
s {$sel:entries:PutPartnerEvents' :: NonEmpty PutPartnerEventsRequestEntry
entries = NonEmpty PutPartnerEventsRequestEntry
a} :: PutPartnerEvents) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PutPartnerEvents where
  type
    AWSResponse PutPartnerEvents =
      PutPartnerEventsResponse
  request :: (Service -> Service)
-> PutPartnerEvents -> Request PutPartnerEvents
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 PutPartnerEvents
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutPartnerEvents)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [PutPartnerEventsResultEntry]
-> Maybe Int -> Int -> PutPartnerEventsResponse
PutPartnerEventsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Entries" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"FailedEntryCount")
            forall (f :: * -> *) a b. Applicative f => 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 PutPartnerEvents where
  hashWithSalt :: Int -> PutPartnerEvents -> Int
hashWithSalt Int
_salt PutPartnerEvents' {NonEmpty PutPartnerEventsRequestEntry
entries :: NonEmpty PutPartnerEventsRequestEntry
$sel:entries:PutPartnerEvents' :: PutPartnerEvents -> NonEmpty PutPartnerEventsRequestEntry
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty PutPartnerEventsRequestEntry
entries

instance Prelude.NFData PutPartnerEvents where
  rnf :: PutPartnerEvents -> ()
rnf PutPartnerEvents' {NonEmpty PutPartnerEventsRequestEntry
entries :: NonEmpty PutPartnerEventsRequestEntry
$sel:entries:PutPartnerEvents' :: PutPartnerEvents -> NonEmpty PutPartnerEventsRequestEntry
..} = forall a. NFData a => a -> ()
Prelude.rnf NonEmpty PutPartnerEventsRequestEntry
entries

instance Data.ToHeaders PutPartnerEvents where
  toHeaders :: PutPartnerEvents -> 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
"AWSEvents.PutPartnerEvents" :: 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 PutPartnerEvents where
  toJSON :: PutPartnerEvents -> Value
toJSON PutPartnerEvents' {NonEmpty PutPartnerEventsRequestEntry
entries :: NonEmpty PutPartnerEventsRequestEntry
$sel:entries:PutPartnerEvents' :: PutPartnerEvents -> NonEmpty PutPartnerEventsRequestEntry
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Entries" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty PutPartnerEventsRequestEntry
entries)]
      )

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

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

-- | /See:/ 'newPutPartnerEventsResponse' smart constructor.
data PutPartnerEventsResponse = PutPartnerEventsResponse'
  { -- | The list of events from this operation that were successfully written to
    -- the partner event bus.
    PutPartnerEventsResponse -> Maybe [PutPartnerEventsResultEntry]
entries :: Prelude.Maybe [PutPartnerEventsResultEntry],
    -- | The number of events from this operation that could not be written to
    -- the partner event bus.
    PutPartnerEventsResponse -> Maybe Int
failedEntryCount :: Prelude.Maybe Prelude.Int,
    -- | The response's http status code.
    PutPartnerEventsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutPartnerEventsResponse -> PutPartnerEventsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutPartnerEventsResponse -> PutPartnerEventsResponse -> Bool
$c/= :: PutPartnerEventsResponse -> PutPartnerEventsResponse -> Bool
== :: PutPartnerEventsResponse -> PutPartnerEventsResponse -> Bool
$c== :: PutPartnerEventsResponse -> PutPartnerEventsResponse -> Bool
Prelude.Eq, ReadPrec [PutPartnerEventsResponse]
ReadPrec PutPartnerEventsResponse
Int -> ReadS PutPartnerEventsResponse
ReadS [PutPartnerEventsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutPartnerEventsResponse]
$creadListPrec :: ReadPrec [PutPartnerEventsResponse]
readPrec :: ReadPrec PutPartnerEventsResponse
$creadPrec :: ReadPrec PutPartnerEventsResponse
readList :: ReadS [PutPartnerEventsResponse]
$creadList :: ReadS [PutPartnerEventsResponse]
readsPrec :: Int -> ReadS PutPartnerEventsResponse
$creadsPrec :: Int -> ReadS PutPartnerEventsResponse
Prelude.Read, Int -> PutPartnerEventsResponse -> ShowS
[PutPartnerEventsResponse] -> ShowS
PutPartnerEventsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutPartnerEventsResponse] -> ShowS
$cshowList :: [PutPartnerEventsResponse] -> ShowS
show :: PutPartnerEventsResponse -> String
$cshow :: PutPartnerEventsResponse -> String
showsPrec :: Int -> PutPartnerEventsResponse -> ShowS
$cshowsPrec :: Int -> PutPartnerEventsResponse -> ShowS
Prelude.Show, forall x.
Rep PutPartnerEventsResponse x -> PutPartnerEventsResponse
forall x.
PutPartnerEventsResponse -> Rep PutPartnerEventsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutPartnerEventsResponse x -> PutPartnerEventsResponse
$cfrom :: forall x.
PutPartnerEventsResponse -> Rep PutPartnerEventsResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutPartnerEventsResponse' 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:
--
-- 'entries', 'putPartnerEventsResponse_entries' - The list of events from this operation that were successfully written to
-- the partner event bus.
--
-- 'failedEntryCount', 'putPartnerEventsResponse_failedEntryCount' - The number of events from this operation that could not be written to
-- the partner event bus.
--
-- 'httpStatus', 'putPartnerEventsResponse_httpStatus' - The response's http status code.
newPutPartnerEventsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutPartnerEventsResponse
newPutPartnerEventsResponse :: Int -> PutPartnerEventsResponse
newPutPartnerEventsResponse Int
pHttpStatus_ =
  PutPartnerEventsResponse'
    { $sel:entries:PutPartnerEventsResponse' :: Maybe [PutPartnerEventsResultEntry]
entries =
        forall a. Maybe a
Prelude.Nothing,
      $sel:failedEntryCount:PutPartnerEventsResponse' :: Maybe Int
failedEntryCount = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutPartnerEventsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of events from this operation that were successfully written to
-- the partner event bus.
putPartnerEventsResponse_entries :: Lens.Lens' PutPartnerEventsResponse (Prelude.Maybe [PutPartnerEventsResultEntry])
putPartnerEventsResponse_entries :: Lens'
  PutPartnerEventsResponse (Maybe [PutPartnerEventsResultEntry])
putPartnerEventsResponse_entries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutPartnerEventsResponse' {Maybe [PutPartnerEventsResultEntry]
entries :: Maybe [PutPartnerEventsResultEntry]
$sel:entries:PutPartnerEventsResponse' :: PutPartnerEventsResponse -> Maybe [PutPartnerEventsResultEntry]
entries} -> Maybe [PutPartnerEventsResultEntry]
entries) (\s :: PutPartnerEventsResponse
s@PutPartnerEventsResponse' {} Maybe [PutPartnerEventsResultEntry]
a -> PutPartnerEventsResponse
s {$sel:entries:PutPartnerEventsResponse' :: Maybe [PutPartnerEventsResultEntry]
entries = Maybe [PutPartnerEventsResultEntry]
a} :: PutPartnerEventsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of events from this operation that could not be written to
-- the partner event bus.
putPartnerEventsResponse_failedEntryCount :: Lens.Lens' PutPartnerEventsResponse (Prelude.Maybe Prelude.Int)
putPartnerEventsResponse_failedEntryCount :: Lens' PutPartnerEventsResponse (Maybe Int)
putPartnerEventsResponse_failedEntryCount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutPartnerEventsResponse' {Maybe Int
failedEntryCount :: Maybe Int
$sel:failedEntryCount:PutPartnerEventsResponse' :: PutPartnerEventsResponse -> Maybe Int
failedEntryCount} -> Maybe Int
failedEntryCount) (\s :: PutPartnerEventsResponse
s@PutPartnerEventsResponse' {} Maybe Int
a -> PutPartnerEventsResponse
s {$sel:failedEntryCount:PutPartnerEventsResponse' :: Maybe Int
failedEntryCount = Maybe Int
a} :: PutPartnerEventsResponse)

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

instance Prelude.NFData PutPartnerEventsResponse where
  rnf :: PutPartnerEventsResponse -> ()
rnf PutPartnerEventsResponse' {Int
Maybe Int
Maybe [PutPartnerEventsResultEntry]
httpStatus :: Int
failedEntryCount :: Maybe Int
entries :: Maybe [PutPartnerEventsResultEntry]
$sel:httpStatus:PutPartnerEventsResponse' :: PutPartnerEventsResponse -> Int
$sel:failedEntryCount:PutPartnerEventsResponse' :: PutPartnerEventsResponse -> Maybe Int
$sel:entries:PutPartnerEventsResponse' :: PutPartnerEventsResponse -> Maybe [PutPartnerEventsResultEntry]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [PutPartnerEventsResultEntry]
entries
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
failedEntryCount
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus