{-# 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.MediaConnect.StartFlow
-- 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 flow.
module Amazonka.MediaConnect.StartFlow
  ( -- * Creating a Request
    StartFlow (..),
    newStartFlow,

    -- * Request Lenses
    startFlow_flowArn,

    -- * Destructuring the Response
    StartFlowResponse (..),
    newStartFlowResponse,

    -- * Response Lenses
    startFlowResponse_status,
    startFlowResponse_flowArn,
    startFlowResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MediaConnect.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStartFlow' smart constructor.
data StartFlow = StartFlow'
  { -- | The ARN of the flow that you want to start.
    StartFlow -> Text
flowArn :: Prelude.Text
  }
  deriving (StartFlow -> StartFlow -> Bool
(StartFlow -> StartFlow -> Bool)
-> (StartFlow -> StartFlow -> Bool) -> Eq StartFlow
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartFlow -> StartFlow -> Bool
$c/= :: StartFlow -> StartFlow -> Bool
== :: StartFlow -> StartFlow -> Bool
$c== :: StartFlow -> StartFlow -> Bool
Prelude.Eq, ReadPrec [StartFlow]
ReadPrec StartFlow
Int -> ReadS StartFlow
ReadS [StartFlow]
(Int -> ReadS StartFlow)
-> ReadS [StartFlow]
-> ReadPrec StartFlow
-> ReadPrec [StartFlow]
-> Read StartFlow
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartFlow]
$creadListPrec :: ReadPrec [StartFlow]
readPrec :: ReadPrec StartFlow
$creadPrec :: ReadPrec StartFlow
readList :: ReadS [StartFlow]
$creadList :: ReadS [StartFlow]
readsPrec :: Int -> ReadS StartFlow
$creadsPrec :: Int -> ReadS StartFlow
Prelude.Read, Int -> StartFlow -> ShowS
[StartFlow] -> ShowS
StartFlow -> String
(Int -> StartFlow -> ShowS)
-> (StartFlow -> String)
-> ([StartFlow] -> ShowS)
-> Show StartFlow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartFlow] -> ShowS
$cshowList :: [StartFlow] -> ShowS
show :: StartFlow -> String
$cshow :: StartFlow -> String
showsPrec :: Int -> StartFlow -> ShowS
$cshowsPrec :: Int -> StartFlow -> ShowS
Prelude.Show, (forall x. StartFlow -> Rep StartFlow x)
-> (forall x. Rep StartFlow x -> StartFlow) -> Generic StartFlow
forall x. Rep StartFlow x -> StartFlow
forall x. StartFlow -> Rep StartFlow x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartFlow x -> StartFlow
$cfrom :: forall x. StartFlow -> Rep StartFlow x
Prelude.Generic)

-- |
-- Create a value of 'StartFlow' 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:
--
-- 'flowArn', 'startFlow_flowArn' - The ARN of the flow that you want to start.
newStartFlow ::
  -- | 'flowArn'
  Prelude.Text ->
  StartFlow
newStartFlow :: Text -> StartFlow
newStartFlow Text
pFlowArn_ =
  StartFlow' :: Text -> StartFlow
StartFlow' {$sel:flowArn:StartFlow' :: Text
flowArn = Text
pFlowArn_}

-- | The ARN of the flow that you want to start.
startFlow_flowArn :: Lens.Lens' StartFlow Prelude.Text
startFlow_flowArn :: (Text -> f Text) -> StartFlow -> f StartFlow
startFlow_flowArn = (StartFlow -> Text)
-> (StartFlow -> Text -> StartFlow)
-> Lens StartFlow StartFlow Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartFlow' {Text
flowArn :: Text
$sel:flowArn:StartFlow' :: StartFlow -> Text
flowArn} -> Text
flowArn) (\s :: StartFlow
s@StartFlow' {} Text
a -> StartFlow
s {$sel:flowArn:StartFlow' :: Text
flowArn = Text
a} :: StartFlow)

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

instance Prelude.NFData StartFlow

instance Core.ToHeaders StartFlow where
  toHeaders :: StartFlow -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartFlow -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 StartFlow where
  toJSON :: StartFlow -> Value
toJSON = Value -> StartFlow -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath StartFlow where
  toPath :: StartFlow -> ByteString
toPath StartFlow' {Text
flowArn :: Text
$sel:flowArn:StartFlow' :: StartFlow -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/flows/start/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
flowArn]

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

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

-- |
-- Create a value of 'StartFlowResponse' 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:
--
-- 'status', 'startFlowResponse_status' - The status of the flow when the StartFlow process begins.
--
-- 'flowArn', 'startFlowResponse_flowArn' - The ARN of the flow that you started.
--
-- 'httpStatus', 'startFlowResponse_httpStatus' - The response's http status code.
newStartFlowResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartFlowResponse
newStartFlowResponse :: Int -> StartFlowResponse
newStartFlowResponse Int
pHttpStatus_ =
  StartFlowResponse' :: Maybe Status -> Maybe Text -> Int -> StartFlowResponse
StartFlowResponse'
    { $sel:status:StartFlowResponse' :: Maybe Status
status = Maybe Status
forall a. Maybe a
Prelude.Nothing,
      $sel:flowArn:StartFlowResponse' :: Maybe Text
flowArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartFlowResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The status of the flow when the StartFlow process begins.
startFlowResponse_status :: Lens.Lens' StartFlowResponse (Prelude.Maybe Status)
startFlowResponse_status :: (Maybe Status -> f (Maybe Status))
-> StartFlowResponse -> f StartFlowResponse
startFlowResponse_status = (StartFlowResponse -> Maybe Status)
-> (StartFlowResponse -> Maybe Status -> StartFlowResponse)
-> Lens
     StartFlowResponse StartFlowResponse (Maybe Status) (Maybe Status)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartFlowResponse' {Maybe Status
status :: Maybe Status
$sel:status:StartFlowResponse' :: StartFlowResponse -> Maybe Status
status} -> Maybe Status
status) (\s :: StartFlowResponse
s@StartFlowResponse' {} Maybe Status
a -> StartFlowResponse
s {$sel:status:StartFlowResponse' :: Maybe Status
status = Maybe Status
a} :: StartFlowResponse)

-- | The ARN of the flow that you started.
startFlowResponse_flowArn :: Lens.Lens' StartFlowResponse (Prelude.Maybe Prelude.Text)
startFlowResponse_flowArn :: (Maybe Text -> f (Maybe Text))
-> StartFlowResponse -> f StartFlowResponse
startFlowResponse_flowArn = (StartFlowResponse -> Maybe Text)
-> (StartFlowResponse -> Maybe Text -> StartFlowResponse)
-> Lens
     StartFlowResponse StartFlowResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartFlowResponse' {Maybe Text
flowArn :: Maybe Text
$sel:flowArn:StartFlowResponse' :: StartFlowResponse -> Maybe Text
flowArn} -> Maybe Text
flowArn) (\s :: StartFlowResponse
s@StartFlowResponse' {} Maybe Text
a -> StartFlowResponse
s {$sel:flowArn:StartFlowResponse' :: Maybe Text
flowArn = Maybe Text
a} :: StartFlowResponse)

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

instance Prelude.NFData StartFlowResponse