{-# 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.IoTThingsGraph.CreateFlowTemplate
-- 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)
--
-- Creates a workflow template. Workflows can be created only in the
-- user\'s namespace. (The public namespace contains only entities.) The
-- workflow can contain only entities in the specified namespace. The
-- workflow is validated against the entities in the latest version of the
-- user\'s namespace unless another namespace version is specified in the
-- request.
module Amazonka.IoTThingsGraph.CreateFlowTemplate
  ( -- * Creating a Request
    CreateFlowTemplate (..),
    newCreateFlowTemplate,

    -- * Request Lenses
    createFlowTemplate_compatibleNamespaceVersion,
    createFlowTemplate_definition,

    -- * Destructuring the Response
    CreateFlowTemplateResponse (..),
    newCreateFlowTemplateResponse,

    -- * Response Lenses
    createFlowTemplateResponse_summary,
    createFlowTemplateResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoTThingsGraph.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:/ 'newCreateFlowTemplate' smart constructor.
data CreateFlowTemplate = CreateFlowTemplate'
  { -- | The namespace version in which the workflow is to be created.
    --
    -- If no value is specified, the latest version is used by default.
    CreateFlowTemplate -> Maybe Integer
compatibleNamespaceVersion :: Prelude.Maybe Prelude.Integer,
    -- | The workflow @DefinitionDocument@.
    CreateFlowTemplate -> DefinitionDocument
definition :: DefinitionDocument
  }
  deriving (CreateFlowTemplate -> CreateFlowTemplate -> Bool
(CreateFlowTemplate -> CreateFlowTemplate -> Bool)
-> (CreateFlowTemplate -> CreateFlowTemplate -> Bool)
-> Eq CreateFlowTemplate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateFlowTemplate -> CreateFlowTemplate -> Bool
$c/= :: CreateFlowTemplate -> CreateFlowTemplate -> Bool
== :: CreateFlowTemplate -> CreateFlowTemplate -> Bool
$c== :: CreateFlowTemplate -> CreateFlowTemplate -> Bool
Prelude.Eq, ReadPrec [CreateFlowTemplate]
ReadPrec CreateFlowTemplate
Int -> ReadS CreateFlowTemplate
ReadS [CreateFlowTemplate]
(Int -> ReadS CreateFlowTemplate)
-> ReadS [CreateFlowTemplate]
-> ReadPrec CreateFlowTemplate
-> ReadPrec [CreateFlowTemplate]
-> Read CreateFlowTemplate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateFlowTemplate]
$creadListPrec :: ReadPrec [CreateFlowTemplate]
readPrec :: ReadPrec CreateFlowTemplate
$creadPrec :: ReadPrec CreateFlowTemplate
readList :: ReadS [CreateFlowTemplate]
$creadList :: ReadS [CreateFlowTemplate]
readsPrec :: Int -> ReadS CreateFlowTemplate
$creadsPrec :: Int -> ReadS CreateFlowTemplate
Prelude.Read, Int -> CreateFlowTemplate -> ShowS
[CreateFlowTemplate] -> ShowS
CreateFlowTemplate -> String
(Int -> CreateFlowTemplate -> ShowS)
-> (CreateFlowTemplate -> String)
-> ([CreateFlowTemplate] -> ShowS)
-> Show CreateFlowTemplate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateFlowTemplate] -> ShowS
$cshowList :: [CreateFlowTemplate] -> ShowS
show :: CreateFlowTemplate -> String
$cshow :: CreateFlowTemplate -> String
showsPrec :: Int -> CreateFlowTemplate -> ShowS
$cshowsPrec :: Int -> CreateFlowTemplate -> ShowS
Prelude.Show, (forall x. CreateFlowTemplate -> Rep CreateFlowTemplate x)
-> (forall x. Rep CreateFlowTemplate x -> CreateFlowTemplate)
-> Generic CreateFlowTemplate
forall x. Rep CreateFlowTemplate x -> CreateFlowTemplate
forall x. CreateFlowTemplate -> Rep CreateFlowTemplate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateFlowTemplate x -> CreateFlowTemplate
$cfrom :: forall x. CreateFlowTemplate -> Rep CreateFlowTemplate x
Prelude.Generic)

-- |
-- Create a value of 'CreateFlowTemplate' 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:
--
-- 'compatibleNamespaceVersion', 'createFlowTemplate_compatibleNamespaceVersion' - The namespace version in which the workflow is to be created.
--
-- If no value is specified, the latest version is used by default.
--
-- 'definition', 'createFlowTemplate_definition' - The workflow @DefinitionDocument@.
newCreateFlowTemplate ::
  -- | 'definition'
  DefinitionDocument ->
  CreateFlowTemplate
newCreateFlowTemplate :: DefinitionDocument -> CreateFlowTemplate
newCreateFlowTemplate DefinitionDocument
pDefinition_ =
  CreateFlowTemplate' :: Maybe Integer -> DefinitionDocument -> CreateFlowTemplate
CreateFlowTemplate'
    { $sel:compatibleNamespaceVersion:CreateFlowTemplate' :: Maybe Integer
compatibleNamespaceVersion =
        Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:definition:CreateFlowTemplate' :: DefinitionDocument
definition = DefinitionDocument
pDefinition_
    }

-- | The namespace version in which the workflow is to be created.
--
-- If no value is specified, the latest version is used by default.
createFlowTemplate_compatibleNamespaceVersion :: Lens.Lens' CreateFlowTemplate (Prelude.Maybe Prelude.Integer)
createFlowTemplate_compatibleNamespaceVersion :: (Maybe Integer -> f (Maybe Integer))
-> CreateFlowTemplate -> f CreateFlowTemplate
createFlowTemplate_compatibleNamespaceVersion = (CreateFlowTemplate -> Maybe Integer)
-> (CreateFlowTemplate -> Maybe Integer -> CreateFlowTemplate)
-> Lens
     CreateFlowTemplate
     CreateFlowTemplate
     (Maybe Integer)
     (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateFlowTemplate' {Maybe Integer
compatibleNamespaceVersion :: Maybe Integer
$sel:compatibleNamespaceVersion:CreateFlowTemplate' :: CreateFlowTemplate -> Maybe Integer
compatibleNamespaceVersion} -> Maybe Integer
compatibleNamespaceVersion) (\s :: CreateFlowTemplate
s@CreateFlowTemplate' {} Maybe Integer
a -> CreateFlowTemplate
s {$sel:compatibleNamespaceVersion:CreateFlowTemplate' :: Maybe Integer
compatibleNamespaceVersion = Maybe Integer
a} :: CreateFlowTemplate)

-- | The workflow @DefinitionDocument@.
createFlowTemplate_definition :: Lens.Lens' CreateFlowTemplate DefinitionDocument
createFlowTemplate_definition :: (DefinitionDocument -> f DefinitionDocument)
-> CreateFlowTemplate -> f CreateFlowTemplate
createFlowTemplate_definition = (CreateFlowTemplate -> DefinitionDocument)
-> (CreateFlowTemplate -> DefinitionDocument -> CreateFlowTemplate)
-> Lens
     CreateFlowTemplate
     CreateFlowTemplate
     DefinitionDocument
     DefinitionDocument
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateFlowTemplate' {DefinitionDocument
definition :: DefinitionDocument
$sel:definition:CreateFlowTemplate' :: CreateFlowTemplate -> DefinitionDocument
definition} -> DefinitionDocument
definition) (\s :: CreateFlowTemplate
s@CreateFlowTemplate' {} DefinitionDocument
a -> CreateFlowTemplate
s {$sel:definition:CreateFlowTemplate' :: DefinitionDocument
definition = DefinitionDocument
a} :: CreateFlowTemplate)

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

instance Prelude.NFData CreateFlowTemplate

instance Core.ToHeaders CreateFlowTemplate where
  toHeaders :: CreateFlowTemplate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateFlowTemplate -> 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
"IotThingsGraphFrontEndService.CreateFlowTemplate" ::
                          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 CreateFlowTemplate where
  toJSON :: CreateFlowTemplate -> Value
toJSON CreateFlowTemplate' {Maybe Integer
DefinitionDocument
definition :: DefinitionDocument
compatibleNamespaceVersion :: Maybe Integer
$sel:definition:CreateFlowTemplate' :: CreateFlowTemplate -> DefinitionDocument
$sel:compatibleNamespaceVersion:CreateFlowTemplate' :: CreateFlowTemplate -> Maybe Integer
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"compatibleNamespaceVersion" Key -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..=)
              (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
compatibleNamespaceVersion,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Key
"definition" Key -> DefinitionDocument -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..= DefinitionDocument
definition)
          ]
      )

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

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

-- | /See:/ 'newCreateFlowTemplateResponse' smart constructor.
data CreateFlowTemplateResponse = CreateFlowTemplateResponse'
  { -- | The summary object that describes the created workflow.
    CreateFlowTemplateResponse -> Maybe FlowTemplateSummary
summary :: Prelude.Maybe FlowTemplateSummary,
    -- | The response's http status code.
    CreateFlowTemplateResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateFlowTemplateResponse -> CreateFlowTemplateResponse -> Bool
(CreateFlowTemplateResponse -> CreateFlowTemplateResponse -> Bool)
-> (CreateFlowTemplateResponse
    -> CreateFlowTemplateResponse -> Bool)
-> Eq CreateFlowTemplateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateFlowTemplateResponse -> CreateFlowTemplateResponse -> Bool
$c/= :: CreateFlowTemplateResponse -> CreateFlowTemplateResponse -> Bool
== :: CreateFlowTemplateResponse -> CreateFlowTemplateResponse -> Bool
$c== :: CreateFlowTemplateResponse -> CreateFlowTemplateResponse -> Bool
Prelude.Eq, ReadPrec [CreateFlowTemplateResponse]
ReadPrec CreateFlowTemplateResponse
Int -> ReadS CreateFlowTemplateResponse
ReadS [CreateFlowTemplateResponse]
(Int -> ReadS CreateFlowTemplateResponse)
-> ReadS [CreateFlowTemplateResponse]
-> ReadPrec CreateFlowTemplateResponse
-> ReadPrec [CreateFlowTemplateResponse]
-> Read CreateFlowTemplateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateFlowTemplateResponse]
$creadListPrec :: ReadPrec [CreateFlowTemplateResponse]
readPrec :: ReadPrec CreateFlowTemplateResponse
$creadPrec :: ReadPrec CreateFlowTemplateResponse
readList :: ReadS [CreateFlowTemplateResponse]
$creadList :: ReadS [CreateFlowTemplateResponse]
readsPrec :: Int -> ReadS CreateFlowTemplateResponse
$creadsPrec :: Int -> ReadS CreateFlowTemplateResponse
Prelude.Read, Int -> CreateFlowTemplateResponse -> ShowS
[CreateFlowTemplateResponse] -> ShowS
CreateFlowTemplateResponse -> String
(Int -> CreateFlowTemplateResponse -> ShowS)
-> (CreateFlowTemplateResponse -> String)
-> ([CreateFlowTemplateResponse] -> ShowS)
-> Show CreateFlowTemplateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateFlowTemplateResponse] -> ShowS
$cshowList :: [CreateFlowTemplateResponse] -> ShowS
show :: CreateFlowTemplateResponse -> String
$cshow :: CreateFlowTemplateResponse -> String
showsPrec :: Int -> CreateFlowTemplateResponse -> ShowS
$cshowsPrec :: Int -> CreateFlowTemplateResponse -> ShowS
Prelude.Show, (forall x.
 CreateFlowTemplateResponse -> Rep CreateFlowTemplateResponse x)
-> (forall x.
    Rep CreateFlowTemplateResponse x -> CreateFlowTemplateResponse)
-> Generic CreateFlowTemplateResponse
forall x.
Rep CreateFlowTemplateResponse x -> CreateFlowTemplateResponse
forall x.
CreateFlowTemplateResponse -> Rep CreateFlowTemplateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateFlowTemplateResponse x -> CreateFlowTemplateResponse
$cfrom :: forall x.
CreateFlowTemplateResponse -> Rep CreateFlowTemplateResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateFlowTemplateResponse' 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:
--
-- 'summary', 'createFlowTemplateResponse_summary' - The summary object that describes the created workflow.
--
-- 'httpStatus', 'createFlowTemplateResponse_httpStatus' - The response's http status code.
newCreateFlowTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateFlowTemplateResponse
newCreateFlowTemplateResponse :: Int -> CreateFlowTemplateResponse
newCreateFlowTemplateResponse Int
pHttpStatus_ =
  CreateFlowTemplateResponse' :: Maybe FlowTemplateSummary -> Int -> CreateFlowTemplateResponse
CreateFlowTemplateResponse'
    { $sel:summary:CreateFlowTemplateResponse' :: Maybe FlowTemplateSummary
summary =
        Maybe FlowTemplateSummary
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateFlowTemplateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The summary object that describes the created workflow.
createFlowTemplateResponse_summary :: Lens.Lens' CreateFlowTemplateResponse (Prelude.Maybe FlowTemplateSummary)
createFlowTemplateResponse_summary :: (Maybe FlowTemplateSummary -> f (Maybe FlowTemplateSummary))
-> CreateFlowTemplateResponse -> f CreateFlowTemplateResponse
createFlowTemplateResponse_summary = (CreateFlowTemplateResponse -> Maybe FlowTemplateSummary)
-> (CreateFlowTemplateResponse
    -> Maybe FlowTemplateSummary -> CreateFlowTemplateResponse)
-> Lens
     CreateFlowTemplateResponse
     CreateFlowTemplateResponse
     (Maybe FlowTemplateSummary)
     (Maybe FlowTemplateSummary)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateFlowTemplateResponse' {Maybe FlowTemplateSummary
summary :: Maybe FlowTemplateSummary
$sel:summary:CreateFlowTemplateResponse' :: CreateFlowTemplateResponse -> Maybe FlowTemplateSummary
summary} -> Maybe FlowTemplateSummary
summary) (\s :: CreateFlowTemplateResponse
s@CreateFlowTemplateResponse' {} Maybe FlowTemplateSummary
a -> CreateFlowTemplateResponse
s {$sel:summary:CreateFlowTemplateResponse' :: Maybe FlowTemplateSummary
summary = Maybe FlowTemplateSummary
a} :: CreateFlowTemplateResponse)

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

instance Prelude.NFData CreateFlowTemplateResponse