{-# 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.StartWorkflowRun
-- 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 a new run of the specified workflow.
module Amazonka.Glue.StartWorkflowRun
  ( -- * Creating a Request
    StartWorkflowRun (..),
    newStartWorkflowRun,

    -- * Request Lenses
    startWorkflowRun_name,

    -- * Destructuring the Response
    StartWorkflowRunResponse (..),
    newStartWorkflowRunResponse,

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

-- |
-- Create a value of 'StartWorkflowRun' 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', 'startWorkflowRun_name' - The name of the workflow to start.
newStartWorkflowRun ::
  -- | 'name'
  Prelude.Text ->
  StartWorkflowRun
newStartWorkflowRun :: Text -> StartWorkflowRun
newStartWorkflowRun Text
pName_ =
  StartWorkflowRun' :: Text -> StartWorkflowRun
StartWorkflowRun' {$sel:name:StartWorkflowRun' :: Text
name = Text
pName_}

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

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

instance Prelude.NFData StartWorkflowRun

instance Core.ToHeaders StartWorkflowRun where
  toHeaders :: StartWorkflowRun -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartWorkflowRun -> 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.StartWorkflowRun" :: 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 StartWorkflowRun where
  toJSON :: StartWorkflowRun -> Value
toJSON StartWorkflowRun' {Text
name :: Text
$sel:name:StartWorkflowRun' :: StartWorkflowRun -> 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 StartWorkflowRun where
  toPath :: StartWorkflowRun -> ByteString
toPath = ByteString -> StartWorkflowRun -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'StartWorkflowRunResponse' 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:
--
-- 'runId', 'startWorkflowRunResponse_runId' - An Id for the new run.
--
-- 'httpStatus', 'startWorkflowRunResponse_httpStatus' - The response's http status code.
newStartWorkflowRunResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartWorkflowRunResponse
newStartWorkflowRunResponse :: Int -> StartWorkflowRunResponse
newStartWorkflowRunResponse Int
pHttpStatus_ =
  StartWorkflowRunResponse' :: Maybe Text -> Int -> StartWorkflowRunResponse
StartWorkflowRunResponse'
    { $sel:runId:StartWorkflowRunResponse' :: Maybe Text
runId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartWorkflowRunResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An Id for the new run.
startWorkflowRunResponse_runId :: Lens.Lens' StartWorkflowRunResponse (Prelude.Maybe Prelude.Text)
startWorkflowRunResponse_runId :: (Maybe Text -> f (Maybe Text))
-> StartWorkflowRunResponse -> f StartWorkflowRunResponse
startWorkflowRunResponse_runId = (StartWorkflowRunResponse -> Maybe Text)
-> (StartWorkflowRunResponse
    -> Maybe Text -> StartWorkflowRunResponse)
-> Lens
     StartWorkflowRunResponse
     StartWorkflowRunResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartWorkflowRunResponse' {Maybe Text
runId :: Maybe Text
$sel:runId:StartWorkflowRunResponse' :: StartWorkflowRunResponse -> Maybe Text
runId} -> Maybe Text
runId) (\s :: StartWorkflowRunResponse
s@StartWorkflowRunResponse' {} Maybe Text
a -> StartWorkflowRunResponse
s {$sel:runId:StartWorkflowRunResponse' :: Maybe Text
runId = Maybe Text
a} :: StartWorkflowRunResponse)

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

instance Prelude.NFData StartWorkflowRunResponse