{-# 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.APIGateway.CreateDocumentationVersion
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a documentation version
module Amazonka.APIGateway.CreateDocumentationVersion
  ( -- * Creating a Request
    CreateDocumentationVersion (..),
    newCreateDocumentationVersion,

    -- * Request Lenses
    createDocumentationVersion_description,
    createDocumentationVersion_stageName,
    createDocumentationVersion_restApiId,
    createDocumentationVersion_documentationVersion,

    -- * Destructuring the Response
    DocumentationVersion (..),
    newDocumentationVersion,

    -- * Response Lenses
    documentationVersion_createdDate,
    documentationVersion_description,
    documentationVersion_version,
  )
where

import Amazonka.APIGateway.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Creates a new documentation version of a given API.
--
-- /See:/ 'newCreateDocumentationVersion' smart constructor.
data CreateDocumentationVersion = CreateDocumentationVersion'
  { -- | A description about the new documentation snapshot.
    CreateDocumentationVersion -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The stage name to be associated with the new documentation snapshot.
    CreateDocumentationVersion -> Maybe Text
stageName :: Prelude.Maybe Prelude.Text,
    -- | The string identifier of the associated RestApi.
    CreateDocumentationVersion -> Text
restApiId :: Prelude.Text,
    -- | The version identifier of the new snapshot.
    CreateDocumentationVersion -> Text
documentationVersion :: Prelude.Text
  }
  deriving (CreateDocumentationVersion -> CreateDocumentationVersion -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateDocumentationVersion -> CreateDocumentationVersion -> Bool
$c/= :: CreateDocumentationVersion -> CreateDocumentationVersion -> Bool
== :: CreateDocumentationVersion -> CreateDocumentationVersion -> Bool
$c== :: CreateDocumentationVersion -> CreateDocumentationVersion -> Bool
Prelude.Eq, ReadPrec [CreateDocumentationVersion]
ReadPrec CreateDocumentationVersion
Int -> ReadS CreateDocumentationVersion
ReadS [CreateDocumentationVersion]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateDocumentationVersion]
$creadListPrec :: ReadPrec [CreateDocumentationVersion]
readPrec :: ReadPrec CreateDocumentationVersion
$creadPrec :: ReadPrec CreateDocumentationVersion
readList :: ReadS [CreateDocumentationVersion]
$creadList :: ReadS [CreateDocumentationVersion]
readsPrec :: Int -> ReadS CreateDocumentationVersion
$creadsPrec :: Int -> ReadS CreateDocumentationVersion
Prelude.Read, Int -> CreateDocumentationVersion -> ShowS
[CreateDocumentationVersion] -> ShowS
CreateDocumentationVersion -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDocumentationVersion] -> ShowS
$cshowList :: [CreateDocumentationVersion] -> ShowS
show :: CreateDocumentationVersion -> String
$cshow :: CreateDocumentationVersion -> String
showsPrec :: Int -> CreateDocumentationVersion -> ShowS
$cshowsPrec :: Int -> CreateDocumentationVersion -> ShowS
Prelude.Show, forall x.
Rep CreateDocumentationVersion x -> CreateDocumentationVersion
forall x.
CreateDocumentationVersion -> Rep CreateDocumentationVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateDocumentationVersion x -> CreateDocumentationVersion
$cfrom :: forall x.
CreateDocumentationVersion -> Rep CreateDocumentationVersion x
Prelude.Generic)

-- |
-- Create a value of 'CreateDocumentationVersion' 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:
--
-- 'description', 'createDocumentationVersion_description' - A description about the new documentation snapshot.
--
-- 'stageName', 'createDocumentationVersion_stageName' - The stage name to be associated with the new documentation snapshot.
--
-- 'restApiId', 'createDocumentationVersion_restApiId' - The string identifier of the associated RestApi.
--
-- 'documentationVersion', 'createDocumentationVersion_documentationVersion' - The version identifier of the new snapshot.
newCreateDocumentationVersion ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'documentationVersion'
  Prelude.Text ->
  CreateDocumentationVersion
newCreateDocumentationVersion :: Text -> Text -> CreateDocumentationVersion
newCreateDocumentationVersion
  Text
pRestApiId_
  Text
pDocumentationVersion_ =
    CreateDocumentationVersion'
      { $sel:description:CreateDocumentationVersion' :: Maybe Text
description =
          forall a. Maybe a
Prelude.Nothing,
        $sel:stageName:CreateDocumentationVersion' :: Maybe Text
stageName = forall a. Maybe a
Prelude.Nothing,
        $sel:restApiId:CreateDocumentationVersion' :: Text
restApiId = Text
pRestApiId_,
        $sel:documentationVersion:CreateDocumentationVersion' :: Text
documentationVersion = Text
pDocumentationVersion_
      }

-- | A description about the new documentation snapshot.
createDocumentationVersion_description :: Lens.Lens' CreateDocumentationVersion (Prelude.Maybe Prelude.Text)
createDocumentationVersion_description :: Lens' CreateDocumentationVersion (Maybe Text)
createDocumentationVersion_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDocumentationVersion' {Maybe Text
description :: Maybe Text
$sel:description:CreateDocumentationVersion' :: CreateDocumentationVersion -> Maybe Text
description} -> Maybe Text
description) (\s :: CreateDocumentationVersion
s@CreateDocumentationVersion' {} Maybe Text
a -> CreateDocumentationVersion
s {$sel:description:CreateDocumentationVersion' :: Maybe Text
description = Maybe Text
a} :: CreateDocumentationVersion)

-- | The stage name to be associated with the new documentation snapshot.
createDocumentationVersion_stageName :: Lens.Lens' CreateDocumentationVersion (Prelude.Maybe Prelude.Text)
createDocumentationVersion_stageName :: Lens' CreateDocumentationVersion (Maybe Text)
createDocumentationVersion_stageName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDocumentationVersion' {Maybe Text
stageName :: Maybe Text
$sel:stageName:CreateDocumentationVersion' :: CreateDocumentationVersion -> Maybe Text
stageName} -> Maybe Text
stageName) (\s :: CreateDocumentationVersion
s@CreateDocumentationVersion' {} Maybe Text
a -> CreateDocumentationVersion
s {$sel:stageName:CreateDocumentationVersion' :: Maybe Text
stageName = Maybe Text
a} :: CreateDocumentationVersion)

-- | The string identifier of the associated RestApi.
createDocumentationVersion_restApiId :: Lens.Lens' CreateDocumentationVersion Prelude.Text
createDocumentationVersion_restApiId :: Lens' CreateDocumentationVersion Text
createDocumentationVersion_restApiId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDocumentationVersion' {Text
restApiId :: Text
$sel:restApiId:CreateDocumentationVersion' :: CreateDocumentationVersion -> Text
restApiId} -> Text
restApiId) (\s :: CreateDocumentationVersion
s@CreateDocumentationVersion' {} Text
a -> CreateDocumentationVersion
s {$sel:restApiId:CreateDocumentationVersion' :: Text
restApiId = Text
a} :: CreateDocumentationVersion)

-- | The version identifier of the new snapshot.
createDocumentationVersion_documentationVersion :: Lens.Lens' CreateDocumentationVersion Prelude.Text
createDocumentationVersion_documentationVersion :: Lens' CreateDocumentationVersion Text
createDocumentationVersion_documentationVersion = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDocumentationVersion' {Text
documentationVersion :: Text
$sel:documentationVersion:CreateDocumentationVersion' :: CreateDocumentationVersion -> Text
documentationVersion} -> Text
documentationVersion) (\s :: CreateDocumentationVersion
s@CreateDocumentationVersion' {} Text
a -> CreateDocumentationVersion
s {$sel:documentationVersion:CreateDocumentationVersion' :: Text
documentationVersion = Text
a} :: CreateDocumentationVersion)

instance Core.AWSRequest CreateDocumentationVersion where
  type
    AWSResponse CreateDocumentationVersion =
      DocumentationVersion
  request :: (Service -> Service)
-> CreateDocumentationVersion -> Request CreateDocumentationVersion
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateDocumentationVersion
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateDocumentationVersion)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)

instance Prelude.Hashable CreateDocumentationVersion where
  hashWithSalt :: Int -> CreateDocumentationVersion -> Int
hashWithSalt Int
_salt CreateDocumentationVersion' {Maybe Text
Text
documentationVersion :: Text
restApiId :: Text
stageName :: Maybe Text
description :: Maybe Text
$sel:documentationVersion:CreateDocumentationVersion' :: CreateDocumentationVersion -> Text
$sel:restApiId:CreateDocumentationVersion' :: CreateDocumentationVersion -> Text
$sel:stageName:CreateDocumentationVersion' :: CreateDocumentationVersion -> Maybe Text
$sel:description:CreateDocumentationVersion' :: CreateDocumentationVersion -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
stageName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
restApiId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
documentationVersion

instance Prelude.NFData CreateDocumentationVersion where
  rnf :: CreateDocumentationVersion -> ()
rnf CreateDocumentationVersion' {Maybe Text
Text
documentationVersion :: Text
restApiId :: Text
stageName :: Maybe Text
description :: Maybe Text
$sel:documentationVersion:CreateDocumentationVersion' :: CreateDocumentationVersion -> Text
$sel:restApiId:CreateDocumentationVersion' :: CreateDocumentationVersion -> Text
$sel:stageName:CreateDocumentationVersion' :: CreateDocumentationVersion -> Maybe Text
$sel:description:CreateDocumentationVersion' :: CreateDocumentationVersion -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
stageName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
restApiId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
documentationVersion

instance Data.ToHeaders CreateDocumentationVersion where
  toHeaders :: CreateDocumentationVersion -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Accept"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# (ByteString
"application/json" :: Prelude.ByteString)
          ]
      )

instance Data.ToJSON CreateDocumentationVersion where
  toJSON :: CreateDocumentationVersion -> Value
toJSON CreateDocumentationVersion' {Maybe Text
Text
documentationVersion :: Text
restApiId :: Text
stageName :: Maybe Text
description :: Maybe Text
$sel:documentationVersion:CreateDocumentationVersion' :: CreateDocumentationVersion -> Text
$sel:restApiId:CreateDocumentationVersion' :: CreateDocumentationVersion -> Text
$sel:stageName:CreateDocumentationVersion' :: CreateDocumentationVersion -> Maybe Text
$sel:description:CreateDocumentationVersion' :: CreateDocumentationVersion -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"description" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            (Key
"stageName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
stageName,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"documentationVersion"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
documentationVersion
              )
          ]
      )

instance Data.ToPath CreateDocumentationVersion where
  toPath :: CreateDocumentationVersion -> ByteString
toPath CreateDocumentationVersion' {Maybe Text
Text
documentationVersion :: Text
restApiId :: Text
stageName :: Maybe Text
description :: Maybe Text
$sel:documentationVersion:CreateDocumentationVersion' :: CreateDocumentationVersion -> Text
$sel:restApiId:CreateDocumentationVersion' :: CreateDocumentationVersion -> Text
$sel:stageName:CreateDocumentationVersion' :: CreateDocumentationVersion -> Maybe Text
$sel:description:CreateDocumentationVersion' :: CreateDocumentationVersion -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/restapis/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
restApiId,
        ByteString
"/documentation/versions"
      ]

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