{-# 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.SMS.GenerateTemplate
-- 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)
--
-- Generates an AWS CloudFormation template based on the current launch
-- configuration and writes it to an Amazon S3 object in the customer’s
-- Amazon S3 bucket.
module Amazonka.SMS.GenerateTemplate
  ( -- * Creating a Request
    GenerateTemplate (..),
    newGenerateTemplate,

    -- * Request Lenses
    generateTemplate_appId,
    generateTemplate_templateFormat,

    -- * Destructuring the Response
    GenerateTemplateResponse (..),
    newGenerateTemplateResponse,

    -- * Response Lenses
    generateTemplateResponse_s3Location,
    generateTemplateResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGenerateTemplate' smart constructor.
data GenerateTemplate = GenerateTemplate'
  { -- | The ID of the application associated with the AWS CloudFormation
    -- template.
    GenerateTemplate -> Maybe Text
appId :: Prelude.Maybe Prelude.Text,
    -- | The format for generating the AWS CloudFormation template.
    GenerateTemplate -> Maybe OutputFormat
templateFormat :: Prelude.Maybe OutputFormat
  }
  deriving (GenerateTemplate -> GenerateTemplate -> Bool
(GenerateTemplate -> GenerateTemplate -> Bool)
-> (GenerateTemplate -> GenerateTemplate -> Bool)
-> Eq GenerateTemplate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GenerateTemplate -> GenerateTemplate -> Bool
$c/= :: GenerateTemplate -> GenerateTemplate -> Bool
== :: GenerateTemplate -> GenerateTemplate -> Bool
$c== :: GenerateTemplate -> GenerateTemplate -> Bool
Prelude.Eq, ReadPrec [GenerateTemplate]
ReadPrec GenerateTemplate
Int -> ReadS GenerateTemplate
ReadS [GenerateTemplate]
(Int -> ReadS GenerateTemplate)
-> ReadS [GenerateTemplate]
-> ReadPrec GenerateTemplate
-> ReadPrec [GenerateTemplate]
-> Read GenerateTemplate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GenerateTemplate]
$creadListPrec :: ReadPrec [GenerateTemplate]
readPrec :: ReadPrec GenerateTemplate
$creadPrec :: ReadPrec GenerateTemplate
readList :: ReadS [GenerateTemplate]
$creadList :: ReadS [GenerateTemplate]
readsPrec :: Int -> ReadS GenerateTemplate
$creadsPrec :: Int -> ReadS GenerateTemplate
Prelude.Read, Int -> GenerateTemplate -> ShowS
[GenerateTemplate] -> ShowS
GenerateTemplate -> String
(Int -> GenerateTemplate -> ShowS)
-> (GenerateTemplate -> String)
-> ([GenerateTemplate] -> ShowS)
-> Show GenerateTemplate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenerateTemplate] -> ShowS
$cshowList :: [GenerateTemplate] -> ShowS
show :: GenerateTemplate -> String
$cshow :: GenerateTemplate -> String
showsPrec :: Int -> GenerateTemplate -> ShowS
$cshowsPrec :: Int -> GenerateTemplate -> ShowS
Prelude.Show, (forall x. GenerateTemplate -> Rep GenerateTemplate x)
-> (forall x. Rep GenerateTemplate x -> GenerateTemplate)
-> Generic GenerateTemplate
forall x. Rep GenerateTemplate x -> GenerateTemplate
forall x. GenerateTemplate -> Rep GenerateTemplate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GenerateTemplate x -> GenerateTemplate
$cfrom :: forall x. GenerateTemplate -> Rep GenerateTemplate x
Prelude.Generic)

-- |
-- Create a value of 'GenerateTemplate' 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:
--
-- 'appId', 'generateTemplate_appId' - The ID of the application associated with the AWS CloudFormation
-- template.
--
-- 'templateFormat', 'generateTemplate_templateFormat' - The format for generating the AWS CloudFormation template.
newGenerateTemplate ::
  GenerateTemplate
newGenerateTemplate :: GenerateTemplate
newGenerateTemplate =
  GenerateTemplate' :: Maybe Text -> Maybe OutputFormat -> GenerateTemplate
GenerateTemplate'
    { $sel:appId:GenerateTemplate' :: Maybe Text
appId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:templateFormat:GenerateTemplate' :: Maybe OutputFormat
templateFormat = Maybe OutputFormat
forall a. Maybe a
Prelude.Nothing
    }

-- | The ID of the application associated with the AWS CloudFormation
-- template.
generateTemplate_appId :: Lens.Lens' GenerateTemplate (Prelude.Maybe Prelude.Text)
generateTemplate_appId :: (Maybe Text -> f (Maybe Text))
-> GenerateTemplate -> f GenerateTemplate
generateTemplate_appId = (GenerateTemplate -> Maybe Text)
-> (GenerateTemplate -> Maybe Text -> GenerateTemplate)
-> Lens GenerateTemplate GenerateTemplate (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GenerateTemplate' {Maybe Text
appId :: Maybe Text
$sel:appId:GenerateTemplate' :: GenerateTemplate -> Maybe Text
appId} -> Maybe Text
appId) (\s :: GenerateTemplate
s@GenerateTemplate' {} Maybe Text
a -> GenerateTemplate
s {$sel:appId:GenerateTemplate' :: Maybe Text
appId = Maybe Text
a} :: GenerateTemplate)

-- | The format for generating the AWS CloudFormation template.
generateTemplate_templateFormat :: Lens.Lens' GenerateTemplate (Prelude.Maybe OutputFormat)
generateTemplate_templateFormat :: (Maybe OutputFormat -> f (Maybe OutputFormat))
-> GenerateTemplate -> f GenerateTemplate
generateTemplate_templateFormat = (GenerateTemplate -> Maybe OutputFormat)
-> (GenerateTemplate -> Maybe OutputFormat -> GenerateTemplate)
-> Lens
     GenerateTemplate
     GenerateTemplate
     (Maybe OutputFormat)
     (Maybe OutputFormat)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GenerateTemplate' {Maybe OutputFormat
templateFormat :: Maybe OutputFormat
$sel:templateFormat:GenerateTemplate' :: GenerateTemplate -> Maybe OutputFormat
templateFormat} -> Maybe OutputFormat
templateFormat) (\s :: GenerateTemplate
s@GenerateTemplate' {} Maybe OutputFormat
a -> GenerateTemplate
s {$sel:templateFormat:GenerateTemplate' :: Maybe OutputFormat
templateFormat = Maybe OutputFormat
a} :: GenerateTemplate)

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

instance Prelude.NFData GenerateTemplate

instance Core.ToHeaders GenerateTemplate where
  toHeaders :: GenerateTemplate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GenerateTemplate -> 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
"AWSServerMigrationService_V2016_10_24.GenerateTemplate" ::
                          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 GenerateTemplate where
  toJSON :: GenerateTemplate -> Value
toJSON GenerateTemplate' {Maybe Text
Maybe OutputFormat
templateFormat :: Maybe OutputFormat
appId :: Maybe Text
$sel:templateFormat:GenerateTemplate' :: GenerateTemplate -> Maybe OutputFormat
$sel:appId:GenerateTemplate' :: GenerateTemplate -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"appId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
appId,
            (Text
"templateFormat" Text -> OutputFormat -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (OutputFormat -> Pair) -> Maybe OutputFormat -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe OutputFormat
templateFormat
          ]
      )

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

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

-- | /See:/ 'newGenerateTemplateResponse' smart constructor.
data GenerateTemplateResponse = GenerateTemplateResponse'
  { -- | The location of the Amazon S3 object.
    GenerateTemplateResponse -> Maybe S3Location
s3Location :: Prelude.Maybe S3Location,
    -- | The response's http status code.
    GenerateTemplateResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GenerateTemplateResponse -> GenerateTemplateResponse -> Bool
(GenerateTemplateResponse -> GenerateTemplateResponse -> Bool)
-> (GenerateTemplateResponse -> GenerateTemplateResponse -> Bool)
-> Eq GenerateTemplateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GenerateTemplateResponse -> GenerateTemplateResponse -> Bool
$c/= :: GenerateTemplateResponse -> GenerateTemplateResponse -> Bool
== :: GenerateTemplateResponse -> GenerateTemplateResponse -> Bool
$c== :: GenerateTemplateResponse -> GenerateTemplateResponse -> Bool
Prelude.Eq, ReadPrec [GenerateTemplateResponse]
ReadPrec GenerateTemplateResponse
Int -> ReadS GenerateTemplateResponse
ReadS [GenerateTemplateResponse]
(Int -> ReadS GenerateTemplateResponse)
-> ReadS [GenerateTemplateResponse]
-> ReadPrec GenerateTemplateResponse
-> ReadPrec [GenerateTemplateResponse]
-> Read GenerateTemplateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GenerateTemplateResponse]
$creadListPrec :: ReadPrec [GenerateTemplateResponse]
readPrec :: ReadPrec GenerateTemplateResponse
$creadPrec :: ReadPrec GenerateTemplateResponse
readList :: ReadS [GenerateTemplateResponse]
$creadList :: ReadS [GenerateTemplateResponse]
readsPrec :: Int -> ReadS GenerateTemplateResponse
$creadsPrec :: Int -> ReadS GenerateTemplateResponse
Prelude.Read, Int -> GenerateTemplateResponse -> ShowS
[GenerateTemplateResponse] -> ShowS
GenerateTemplateResponse -> String
(Int -> GenerateTemplateResponse -> ShowS)
-> (GenerateTemplateResponse -> String)
-> ([GenerateTemplateResponse] -> ShowS)
-> Show GenerateTemplateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenerateTemplateResponse] -> ShowS
$cshowList :: [GenerateTemplateResponse] -> ShowS
show :: GenerateTemplateResponse -> String
$cshow :: GenerateTemplateResponse -> String
showsPrec :: Int -> GenerateTemplateResponse -> ShowS
$cshowsPrec :: Int -> GenerateTemplateResponse -> ShowS
Prelude.Show, (forall x.
 GenerateTemplateResponse -> Rep GenerateTemplateResponse x)
-> (forall x.
    Rep GenerateTemplateResponse x -> GenerateTemplateResponse)
-> Generic GenerateTemplateResponse
forall x.
Rep GenerateTemplateResponse x -> GenerateTemplateResponse
forall x.
GenerateTemplateResponse -> Rep GenerateTemplateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GenerateTemplateResponse x -> GenerateTemplateResponse
$cfrom :: forall x.
GenerateTemplateResponse -> Rep GenerateTemplateResponse x
Prelude.Generic)

-- |
-- Create a value of 'GenerateTemplateResponse' 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:
--
-- 's3Location', 'generateTemplateResponse_s3Location' - The location of the Amazon S3 object.
--
-- 'httpStatus', 'generateTemplateResponse_httpStatus' - The response's http status code.
newGenerateTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GenerateTemplateResponse
newGenerateTemplateResponse :: Int -> GenerateTemplateResponse
newGenerateTemplateResponse Int
pHttpStatus_ =
  GenerateTemplateResponse' :: Maybe S3Location -> Int -> GenerateTemplateResponse
GenerateTemplateResponse'
    { $sel:s3Location:GenerateTemplateResponse' :: Maybe S3Location
s3Location =
        Maybe S3Location
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GenerateTemplateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The location of the Amazon S3 object.
generateTemplateResponse_s3Location :: Lens.Lens' GenerateTemplateResponse (Prelude.Maybe S3Location)
generateTemplateResponse_s3Location :: (Maybe S3Location -> f (Maybe S3Location))
-> GenerateTemplateResponse -> f GenerateTemplateResponse
generateTemplateResponse_s3Location = (GenerateTemplateResponse -> Maybe S3Location)
-> (GenerateTemplateResponse
    -> Maybe S3Location -> GenerateTemplateResponse)
-> Lens
     GenerateTemplateResponse
     GenerateTemplateResponse
     (Maybe S3Location)
     (Maybe S3Location)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GenerateTemplateResponse' {Maybe S3Location
s3Location :: Maybe S3Location
$sel:s3Location:GenerateTemplateResponse' :: GenerateTemplateResponse -> Maybe S3Location
s3Location} -> Maybe S3Location
s3Location) (\s :: GenerateTemplateResponse
s@GenerateTemplateResponse' {} Maybe S3Location
a -> GenerateTemplateResponse
s {$sel:s3Location:GenerateTemplateResponse' :: Maybe S3Location
s3Location = Maybe S3Location
a} :: GenerateTemplateResponse)

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

instance Prelude.NFData GenerateTemplateResponse