{-# 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.CreateDocumentationPart
-- 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)
--
-- -- | Undocumented operation.
module Amazonka.APIGateway.CreateDocumentationPart
  ( -- * Creating a Request
    CreateDocumentationPart (..),
    newCreateDocumentationPart,

    -- * Request Lenses
    createDocumentationPart_restApiId,
    createDocumentationPart_location,
    createDocumentationPart_properties,

    -- * Destructuring the Response
    DocumentationPart (..),
    newDocumentationPart,

    -- * Response Lenses
    documentationPart_location,
    documentationPart_id,
    documentationPart_properties,
  )
where

import Amazonka.APIGateway.Types
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

-- | Creates a new documentation part of a given API.
--
-- /See:/ 'newCreateDocumentationPart' smart constructor.
data CreateDocumentationPart = CreateDocumentationPart'
  { -- | [Required] The string identifier of the associated RestApi.
    CreateDocumentationPart -> Text
restApiId :: Prelude.Text,
    -- | [Required] The location of the targeted API entity of the to-be-created
    -- documentation part.
    CreateDocumentationPart -> DocumentationPartLocation
location :: DocumentationPartLocation,
    -- | [Required] The new documentation content map of the targeted API entity.
    -- Enclosed key-value pairs are API-specific, but only OpenAPI-compliant
    -- key-value pairs can be exported and, hence, published.
    CreateDocumentationPart -> Text
properties :: Prelude.Text
  }
  deriving (CreateDocumentationPart -> CreateDocumentationPart -> Bool
(CreateDocumentationPart -> CreateDocumentationPart -> Bool)
-> (CreateDocumentationPart -> CreateDocumentationPart -> Bool)
-> Eq CreateDocumentationPart
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateDocumentationPart -> CreateDocumentationPart -> Bool
$c/= :: CreateDocumentationPart -> CreateDocumentationPart -> Bool
== :: CreateDocumentationPart -> CreateDocumentationPart -> Bool
$c== :: CreateDocumentationPart -> CreateDocumentationPart -> Bool
Prelude.Eq, ReadPrec [CreateDocumentationPart]
ReadPrec CreateDocumentationPart
Int -> ReadS CreateDocumentationPart
ReadS [CreateDocumentationPart]
(Int -> ReadS CreateDocumentationPart)
-> ReadS [CreateDocumentationPart]
-> ReadPrec CreateDocumentationPart
-> ReadPrec [CreateDocumentationPart]
-> Read CreateDocumentationPart
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateDocumentationPart]
$creadListPrec :: ReadPrec [CreateDocumentationPart]
readPrec :: ReadPrec CreateDocumentationPart
$creadPrec :: ReadPrec CreateDocumentationPart
readList :: ReadS [CreateDocumentationPart]
$creadList :: ReadS [CreateDocumentationPart]
readsPrec :: Int -> ReadS CreateDocumentationPart
$creadsPrec :: Int -> ReadS CreateDocumentationPart
Prelude.Read, Int -> CreateDocumentationPart -> ShowS
[CreateDocumentationPart] -> ShowS
CreateDocumentationPart -> String
(Int -> CreateDocumentationPart -> ShowS)
-> (CreateDocumentationPart -> String)
-> ([CreateDocumentationPart] -> ShowS)
-> Show CreateDocumentationPart
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDocumentationPart] -> ShowS
$cshowList :: [CreateDocumentationPart] -> ShowS
show :: CreateDocumentationPart -> String
$cshow :: CreateDocumentationPart -> String
showsPrec :: Int -> CreateDocumentationPart -> ShowS
$cshowsPrec :: Int -> CreateDocumentationPart -> ShowS
Prelude.Show, (forall x.
 CreateDocumentationPart -> Rep CreateDocumentationPart x)
-> (forall x.
    Rep CreateDocumentationPart x -> CreateDocumentationPart)
-> Generic CreateDocumentationPart
forall x. Rep CreateDocumentationPart x -> CreateDocumentationPart
forall x. CreateDocumentationPart -> Rep CreateDocumentationPart x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateDocumentationPart x -> CreateDocumentationPart
$cfrom :: forall x. CreateDocumentationPart -> Rep CreateDocumentationPart x
Prelude.Generic)

-- |
-- Create a value of 'CreateDocumentationPart' 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:
--
-- 'restApiId', 'createDocumentationPart_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'location', 'createDocumentationPart_location' - [Required] The location of the targeted API entity of the to-be-created
-- documentation part.
--
-- 'properties', 'createDocumentationPart_properties' - [Required] The new documentation content map of the targeted API entity.
-- Enclosed key-value pairs are API-specific, but only OpenAPI-compliant
-- key-value pairs can be exported and, hence, published.
newCreateDocumentationPart ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'location'
  DocumentationPartLocation ->
  -- | 'properties'
  Prelude.Text ->
  CreateDocumentationPart
newCreateDocumentationPart :: Text
-> DocumentationPartLocation -> Text -> CreateDocumentationPart
newCreateDocumentationPart
  Text
pRestApiId_
  DocumentationPartLocation
pLocation_
  Text
pProperties_ =
    CreateDocumentationPart' :: Text
-> DocumentationPartLocation -> Text -> CreateDocumentationPart
CreateDocumentationPart'
      { $sel:restApiId:CreateDocumentationPart' :: Text
restApiId = Text
pRestApiId_,
        $sel:location:CreateDocumentationPart' :: DocumentationPartLocation
location = DocumentationPartLocation
pLocation_,
        $sel:properties:CreateDocumentationPart' :: Text
properties = Text
pProperties_
      }

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

-- | [Required] The location of the targeted API entity of the to-be-created
-- documentation part.
createDocumentationPart_location :: Lens.Lens' CreateDocumentationPart DocumentationPartLocation
createDocumentationPart_location :: (DocumentationPartLocation -> f DocumentationPartLocation)
-> CreateDocumentationPart -> f CreateDocumentationPart
createDocumentationPart_location = (CreateDocumentationPart -> DocumentationPartLocation)
-> (CreateDocumentationPart
    -> DocumentationPartLocation -> CreateDocumentationPart)
-> Lens
     CreateDocumentationPart
     CreateDocumentationPart
     DocumentationPartLocation
     DocumentationPartLocation
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDocumentationPart' {DocumentationPartLocation
location :: DocumentationPartLocation
$sel:location:CreateDocumentationPart' :: CreateDocumentationPart -> DocumentationPartLocation
location} -> DocumentationPartLocation
location) (\s :: CreateDocumentationPart
s@CreateDocumentationPart' {} DocumentationPartLocation
a -> CreateDocumentationPart
s {$sel:location:CreateDocumentationPart' :: DocumentationPartLocation
location = DocumentationPartLocation
a} :: CreateDocumentationPart)

-- | [Required] The new documentation content map of the targeted API entity.
-- Enclosed key-value pairs are API-specific, but only OpenAPI-compliant
-- key-value pairs can be exported and, hence, published.
createDocumentationPart_properties :: Lens.Lens' CreateDocumentationPart Prelude.Text
createDocumentationPart_properties :: (Text -> f Text)
-> CreateDocumentationPart -> f CreateDocumentationPart
createDocumentationPart_properties = (CreateDocumentationPart -> Text)
-> (CreateDocumentationPart -> Text -> CreateDocumentationPart)
-> Lens CreateDocumentationPart CreateDocumentationPart Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDocumentationPart' {Text
properties :: Text
$sel:properties:CreateDocumentationPart' :: CreateDocumentationPart -> Text
properties} -> Text
properties) (\s :: CreateDocumentationPart
s@CreateDocumentationPart' {} Text
a -> CreateDocumentationPart
s {$sel:properties:CreateDocumentationPart' :: Text
properties = Text
a} :: CreateDocumentationPart)

instance Core.AWSRequest CreateDocumentationPart where
  type
    AWSResponse CreateDocumentationPart =
      DocumentationPart
  request :: CreateDocumentationPart -> Request CreateDocumentationPart
request = Service
-> CreateDocumentationPart -> Request CreateDocumentationPart
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateDocumentationPart
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateDocumentationPart)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateDocumentationPart))
-> Logger
-> Service
-> Proxy CreateDocumentationPart
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateDocumentationPart)))
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 -> Object -> Either String DocumentationPart
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable CreateDocumentationPart

instance Prelude.NFData CreateDocumentationPart

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

instance Core.ToJSON CreateDocumentationPart where
  toJSON :: CreateDocumentationPart -> Value
toJSON CreateDocumentationPart' {Text
DocumentationPartLocation
properties :: Text
location :: DocumentationPartLocation
restApiId :: Text
$sel:properties:CreateDocumentationPart' :: CreateDocumentationPart -> Text
$sel:location:CreateDocumentationPart' :: CreateDocumentationPart -> DocumentationPartLocation
$sel:restApiId:CreateDocumentationPart' :: CreateDocumentationPart -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"location" Text -> DocumentationPartLocation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= DocumentationPartLocation
location),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"properties" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
properties)
          ]
      )

instance Core.ToPath CreateDocumentationPart where
  toPath :: CreateDocumentationPart -> ByteString
toPath CreateDocumentationPart' {Text
DocumentationPartLocation
properties :: Text
location :: DocumentationPartLocation
restApiId :: Text
$sel:properties:CreateDocumentationPart' :: CreateDocumentationPart -> Text
$sel:location:CreateDocumentationPart' :: CreateDocumentationPart -> DocumentationPartLocation
$sel:restApiId:CreateDocumentationPart' :: CreateDocumentationPart -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/restapis/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
restApiId,
        ByteString
"/documentation/parts"
      ]

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