{-# 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.StartTrigger
-- 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)
--
-- Starts an existing trigger. See
-- <https://docs.aws.amazon.com/glue/latest/dg/trigger-job.html Triggering Jobs>
-- for information about how different types of trigger are started.
module Amazonka.Glue.StartTrigger
  ( -- * Creating a Request
    StartTrigger (..),
    newStartTrigger,

    -- * Request Lenses
    startTrigger_name,

    -- * Destructuring the Response
    StartTriggerResponse (..),
    newStartTriggerResponse,

    -- * Response Lenses
    startTriggerResponse_name,
    startTriggerResponse_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:/ 'newStartTrigger' smart constructor.
data StartTrigger = StartTrigger'
  { -- | The name of the trigger to start.
    StartTrigger -> Text
name :: Prelude.Text
  }
  deriving (StartTrigger -> StartTrigger -> Bool
(StartTrigger -> StartTrigger -> Bool)
-> (StartTrigger -> StartTrigger -> Bool) -> Eq StartTrigger
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartTrigger -> StartTrigger -> Bool
$c/= :: StartTrigger -> StartTrigger -> Bool
== :: StartTrigger -> StartTrigger -> Bool
$c== :: StartTrigger -> StartTrigger -> Bool
Prelude.Eq, ReadPrec [StartTrigger]
ReadPrec StartTrigger
Int -> ReadS StartTrigger
ReadS [StartTrigger]
(Int -> ReadS StartTrigger)
-> ReadS [StartTrigger]
-> ReadPrec StartTrigger
-> ReadPrec [StartTrigger]
-> Read StartTrigger
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartTrigger]
$creadListPrec :: ReadPrec [StartTrigger]
readPrec :: ReadPrec StartTrigger
$creadPrec :: ReadPrec StartTrigger
readList :: ReadS [StartTrigger]
$creadList :: ReadS [StartTrigger]
readsPrec :: Int -> ReadS StartTrigger
$creadsPrec :: Int -> ReadS StartTrigger
Prelude.Read, Int -> StartTrigger -> ShowS
[StartTrigger] -> ShowS
StartTrigger -> String
(Int -> StartTrigger -> ShowS)
-> (StartTrigger -> String)
-> ([StartTrigger] -> ShowS)
-> Show StartTrigger
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartTrigger] -> ShowS
$cshowList :: [StartTrigger] -> ShowS
show :: StartTrigger -> String
$cshow :: StartTrigger -> String
showsPrec :: Int -> StartTrigger -> ShowS
$cshowsPrec :: Int -> StartTrigger -> ShowS
Prelude.Show, (forall x. StartTrigger -> Rep StartTrigger x)
-> (forall x. Rep StartTrigger x -> StartTrigger)
-> Generic StartTrigger
forall x. Rep StartTrigger x -> StartTrigger
forall x. StartTrigger -> Rep StartTrigger x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartTrigger x -> StartTrigger
$cfrom :: forall x. StartTrigger -> Rep StartTrigger x
Prelude.Generic)

-- |
-- Create a value of 'StartTrigger' 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', 'startTrigger_name' - The name of the trigger to start.
newStartTrigger ::
  -- | 'name'
  Prelude.Text ->
  StartTrigger
newStartTrigger :: Text -> StartTrigger
newStartTrigger Text
pName_ = StartTrigger' :: Text -> StartTrigger
StartTrigger' {$sel:name:StartTrigger' :: Text
name = Text
pName_}

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

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

instance Prelude.NFData StartTrigger

instance Core.ToHeaders StartTrigger where
  toHeaders :: StartTrigger -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartTrigger -> 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.StartTrigger" :: 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 StartTrigger where
  toJSON :: StartTrigger -> Value
toJSON StartTrigger' {Text
name :: Text
$sel:name:StartTrigger' :: StartTrigger -> 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)]
      )

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

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

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

-- |
-- Create a value of 'StartTriggerResponse' 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', 'startTriggerResponse_name' - The name of the trigger that was started.
--
-- 'httpStatus', 'startTriggerResponse_httpStatus' - The response's http status code.
newStartTriggerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartTriggerResponse
newStartTriggerResponse :: Int -> StartTriggerResponse
newStartTriggerResponse Int
pHttpStatus_ =
  StartTriggerResponse' :: Maybe Text -> Int -> StartTriggerResponse
StartTriggerResponse'
    { $sel:name:StartTriggerResponse' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartTriggerResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The name of the trigger that was started.
startTriggerResponse_name :: Lens.Lens' StartTriggerResponse (Prelude.Maybe Prelude.Text)
startTriggerResponse_name :: (Maybe Text -> f (Maybe Text))
-> StartTriggerResponse -> f StartTriggerResponse
startTriggerResponse_name = (StartTriggerResponse -> Maybe Text)
-> (StartTriggerResponse -> Maybe Text -> StartTriggerResponse)
-> Lens
     StartTriggerResponse StartTriggerResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartTriggerResponse' {Maybe Text
name :: Maybe Text
$sel:name:StartTriggerResponse' :: StartTriggerResponse -> Maybe Text
name} -> Maybe Text
name) (\s :: StartTriggerResponse
s@StartTriggerResponse' {} Maybe Text
a -> StartTriggerResponse
s {$sel:name:StartTriggerResponse' :: Maybe Text
name = Maybe Text
a} :: StartTriggerResponse)

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

instance Prelude.NFData StartTriggerResponse