{-# 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.CreateSystemTemplate
-- 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 system. The system 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.CreateSystemTemplate
  ( -- * Creating a Request
    CreateSystemTemplate (..),
    newCreateSystemTemplate,

    -- * Request Lenses
    createSystemTemplate_compatibleNamespaceVersion,
    createSystemTemplate_definition,

    -- * Destructuring the Response
    CreateSystemTemplateResponse (..),
    newCreateSystemTemplateResponse,

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

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

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

-- | The @DefinitionDocument@ used to create the system.
createSystemTemplate_definition :: Lens.Lens' CreateSystemTemplate DefinitionDocument
createSystemTemplate_definition :: (DefinitionDocument -> f DefinitionDocument)
-> CreateSystemTemplate -> f CreateSystemTemplate
createSystemTemplate_definition = (CreateSystemTemplate -> DefinitionDocument)
-> (CreateSystemTemplate
    -> DefinitionDocument -> CreateSystemTemplate)
-> Lens
     CreateSystemTemplate
     CreateSystemTemplate
     DefinitionDocument
     DefinitionDocument
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSystemTemplate' {DefinitionDocument
definition :: DefinitionDocument
$sel:definition:CreateSystemTemplate' :: CreateSystemTemplate -> DefinitionDocument
definition} -> DefinitionDocument
definition) (\s :: CreateSystemTemplate
s@CreateSystemTemplate' {} DefinitionDocument
a -> CreateSystemTemplate
s {$sel:definition:CreateSystemTemplate' :: DefinitionDocument
definition = DefinitionDocument
a} :: CreateSystemTemplate)

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

instance Prelude.NFData CreateSystemTemplate

instance Core.ToHeaders CreateSystemTemplate where
  toHeaders :: CreateSystemTemplate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateSystemTemplate -> 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.CreateSystemTemplate" ::
                          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 CreateSystemTemplate where
  toJSON :: CreateSystemTemplate -> Value
toJSON CreateSystemTemplate' {Maybe Integer
DefinitionDocument
definition :: DefinitionDocument
compatibleNamespaceVersion :: Maybe Integer
$sel:definition:CreateSystemTemplate' :: CreateSystemTemplate -> DefinitionDocument
$sel:compatibleNamespaceVersion:CreateSystemTemplate' :: CreateSystemTemplate -> 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 CreateSystemTemplate where
  toPath :: CreateSystemTemplate -> ByteString
toPath = ByteString -> CreateSystemTemplate -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'CreateSystemTemplateResponse' 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', 'createSystemTemplateResponse_summary' - The summary object that describes the created system.
--
-- 'httpStatus', 'createSystemTemplateResponse_httpStatus' - The response's http status code.
newCreateSystemTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateSystemTemplateResponse
newCreateSystemTemplateResponse :: Int -> CreateSystemTemplateResponse
newCreateSystemTemplateResponse Int
pHttpStatus_ =
  CreateSystemTemplateResponse' :: Maybe SystemTemplateSummary -> Int -> CreateSystemTemplateResponse
CreateSystemTemplateResponse'
    { $sel:summary:CreateSystemTemplateResponse' :: Maybe SystemTemplateSummary
summary =
        Maybe SystemTemplateSummary
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateSystemTemplateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

instance Prelude.NFData CreateSystemTemplateResponse