{-# 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.Glue.UpdateTrigger
-- 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)
--
-- Updates a trigger definition.
module Amazonka.Glue.UpdateTrigger
  ( -- * Creating a Request
    UpdateTrigger (..),
    newUpdateTrigger,

    -- * Request Lenses
    updateTrigger_name,
    updateTrigger_triggerUpdate,

    -- * Destructuring the Response
    UpdateTriggerResponse (..),
    newUpdateTriggerResponse,

    -- * Response Lenses
    updateTriggerResponse_trigger,
    updateTriggerResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Glue.Types
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:/ 'newUpdateTrigger' smart constructor.
data UpdateTrigger = UpdateTrigger'
  { -- | The name of the trigger to update.
    UpdateTrigger -> Text
name :: Prelude.Text,
    -- | The new values with which to update the trigger.
    UpdateTrigger -> TriggerUpdate
triggerUpdate :: TriggerUpdate
  }
  deriving (UpdateTrigger -> UpdateTrigger -> Bool
(UpdateTrigger -> UpdateTrigger -> Bool)
-> (UpdateTrigger -> UpdateTrigger -> Bool) -> Eq UpdateTrigger
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateTrigger -> UpdateTrigger -> Bool
$c/= :: UpdateTrigger -> UpdateTrigger -> Bool
== :: UpdateTrigger -> UpdateTrigger -> Bool
$c== :: UpdateTrigger -> UpdateTrigger -> Bool
Prelude.Eq, ReadPrec [UpdateTrigger]
ReadPrec UpdateTrigger
Int -> ReadS UpdateTrigger
ReadS [UpdateTrigger]
(Int -> ReadS UpdateTrigger)
-> ReadS [UpdateTrigger]
-> ReadPrec UpdateTrigger
-> ReadPrec [UpdateTrigger]
-> Read UpdateTrigger
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateTrigger]
$creadListPrec :: ReadPrec [UpdateTrigger]
readPrec :: ReadPrec UpdateTrigger
$creadPrec :: ReadPrec UpdateTrigger
readList :: ReadS [UpdateTrigger]
$creadList :: ReadS [UpdateTrigger]
readsPrec :: Int -> ReadS UpdateTrigger
$creadsPrec :: Int -> ReadS UpdateTrigger
Prelude.Read, Int -> UpdateTrigger -> ShowS
[UpdateTrigger] -> ShowS
UpdateTrigger -> String
(Int -> UpdateTrigger -> ShowS)
-> (UpdateTrigger -> String)
-> ([UpdateTrigger] -> ShowS)
-> Show UpdateTrigger
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateTrigger] -> ShowS
$cshowList :: [UpdateTrigger] -> ShowS
show :: UpdateTrigger -> String
$cshow :: UpdateTrigger -> String
showsPrec :: Int -> UpdateTrigger -> ShowS
$cshowsPrec :: Int -> UpdateTrigger -> ShowS
Prelude.Show, (forall x. UpdateTrigger -> Rep UpdateTrigger x)
-> (forall x. Rep UpdateTrigger x -> UpdateTrigger)
-> Generic UpdateTrigger
forall x. Rep UpdateTrigger x -> UpdateTrigger
forall x. UpdateTrigger -> Rep UpdateTrigger x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateTrigger x -> UpdateTrigger
$cfrom :: forall x. UpdateTrigger -> Rep UpdateTrigger x
Prelude.Generic)

-- |
-- Create a value of 'UpdateTrigger' 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', 'updateTrigger_name' - The name of the trigger to update.
--
-- 'triggerUpdate', 'updateTrigger_triggerUpdate' - The new values with which to update the trigger.
newUpdateTrigger ::
  -- | 'name'
  Prelude.Text ->
  -- | 'triggerUpdate'
  TriggerUpdate ->
  UpdateTrigger
newUpdateTrigger :: Text -> TriggerUpdate -> UpdateTrigger
newUpdateTrigger Text
pName_ TriggerUpdate
pTriggerUpdate_ =
  UpdateTrigger' :: Text -> TriggerUpdate -> UpdateTrigger
UpdateTrigger'
    { $sel:name:UpdateTrigger' :: Text
name = Text
pName_,
      $sel:triggerUpdate:UpdateTrigger' :: TriggerUpdate
triggerUpdate = TriggerUpdate
pTriggerUpdate_
    }

-- | The name of the trigger to update.
updateTrigger_name :: Lens.Lens' UpdateTrigger Prelude.Text
updateTrigger_name :: (Text -> f Text) -> UpdateTrigger -> f UpdateTrigger
updateTrigger_name = (UpdateTrigger -> Text)
-> (UpdateTrigger -> Text -> UpdateTrigger)
-> Lens UpdateTrigger UpdateTrigger Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTrigger' {Text
name :: Text
$sel:name:UpdateTrigger' :: UpdateTrigger -> Text
name} -> Text
name) (\s :: UpdateTrigger
s@UpdateTrigger' {} Text
a -> UpdateTrigger
s {$sel:name:UpdateTrigger' :: Text
name = Text
a} :: UpdateTrigger)

-- | The new values with which to update the trigger.
updateTrigger_triggerUpdate :: Lens.Lens' UpdateTrigger TriggerUpdate
updateTrigger_triggerUpdate :: (TriggerUpdate -> f TriggerUpdate)
-> UpdateTrigger -> f UpdateTrigger
updateTrigger_triggerUpdate = (UpdateTrigger -> TriggerUpdate)
-> (UpdateTrigger -> TriggerUpdate -> UpdateTrigger)
-> Lens UpdateTrigger UpdateTrigger TriggerUpdate TriggerUpdate
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTrigger' {TriggerUpdate
triggerUpdate :: TriggerUpdate
$sel:triggerUpdate:UpdateTrigger' :: UpdateTrigger -> TriggerUpdate
triggerUpdate} -> TriggerUpdate
triggerUpdate) (\s :: UpdateTrigger
s@UpdateTrigger' {} TriggerUpdate
a -> UpdateTrigger
s {$sel:triggerUpdate:UpdateTrigger' :: TriggerUpdate
triggerUpdate = TriggerUpdate
a} :: UpdateTrigger)

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

instance Prelude.NFData UpdateTrigger

instance Core.ToHeaders UpdateTrigger where
  toHeaders :: UpdateTrigger -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateTrigger -> 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
"AWSGlue.UpdateTrigger" :: 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 UpdateTrigger where
  toJSON :: UpdateTrigger -> Value
toJSON UpdateTrigger' {Text
TriggerUpdate
triggerUpdate :: TriggerUpdate
name :: Text
$sel:triggerUpdate:UpdateTrigger' :: UpdateTrigger -> TriggerUpdate
$sel:name:UpdateTrigger' :: UpdateTrigger -> 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
"TriggerUpdate" Text -> TriggerUpdate -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= TriggerUpdate
triggerUpdate)
          ]
      )

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

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

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

-- |
-- Create a value of 'UpdateTriggerResponse' 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:
--
-- 'trigger', 'updateTriggerResponse_trigger' - The resulting trigger definition.
--
-- 'httpStatus', 'updateTriggerResponse_httpStatus' - The response's http status code.
newUpdateTriggerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateTriggerResponse
newUpdateTriggerResponse :: Int -> UpdateTriggerResponse
newUpdateTriggerResponse Int
pHttpStatus_ =
  UpdateTriggerResponse' :: Maybe Trigger -> Int -> UpdateTriggerResponse
UpdateTriggerResponse'
    { $sel:trigger:UpdateTriggerResponse' :: Maybe Trigger
trigger = Maybe Trigger
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdateTriggerResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The resulting trigger definition.
updateTriggerResponse_trigger :: Lens.Lens' UpdateTriggerResponse (Prelude.Maybe Trigger)
updateTriggerResponse_trigger :: (Maybe Trigger -> f (Maybe Trigger))
-> UpdateTriggerResponse -> f UpdateTriggerResponse
updateTriggerResponse_trigger = (UpdateTriggerResponse -> Maybe Trigger)
-> (UpdateTriggerResponse
    -> Maybe Trigger -> UpdateTriggerResponse)
-> Lens
     UpdateTriggerResponse
     UpdateTriggerResponse
     (Maybe Trigger)
     (Maybe Trigger)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTriggerResponse' {Maybe Trigger
trigger :: Maybe Trigger
$sel:trigger:UpdateTriggerResponse' :: UpdateTriggerResponse -> Maybe Trigger
trigger} -> Maybe Trigger
trigger) (\s :: UpdateTriggerResponse
s@UpdateTriggerResponse' {} Maybe Trigger
a -> UpdateTriggerResponse
s {$sel:trigger:UpdateTriggerResponse' :: Maybe Trigger
trigger = Maybe Trigger
a} :: UpdateTriggerResponse)

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

instance Prelude.NFData UpdateTriggerResponse