{-# 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.CreateResource
-- 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 Resource resource.
module Amazonka.APIGateway.CreateResource
  ( -- * Creating a Request
    CreateResource (..),
    newCreateResource,

    -- * Request Lenses
    createResource_restApiId,
    createResource_parentId,
    createResource_pathPart,

    -- * Destructuring the Response
    Resource (..),
    newResource,

    -- * Response Lenses
    resource_pathPart,
    resource_path,
    resource_id,
    resource_resourceMethods,
    resource_parentId,
  )
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

-- | Requests API Gateway to create a Resource resource.
--
-- /See:/ 'newCreateResource' smart constructor.
data CreateResource = CreateResource'
  { -- | [Required] The string identifier of the associated RestApi.
    CreateResource -> Text
restApiId :: Prelude.Text,
    -- | [Required] The parent resource\'s identifier.
    CreateResource -> Text
parentId :: Prelude.Text,
    -- | The last path segment for this resource.
    CreateResource -> Text
pathPart :: Prelude.Text
  }
  deriving (CreateResource -> CreateResource -> Bool
(CreateResource -> CreateResource -> Bool)
-> (CreateResource -> CreateResource -> Bool) -> Eq CreateResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateResource -> CreateResource -> Bool
$c/= :: CreateResource -> CreateResource -> Bool
== :: CreateResource -> CreateResource -> Bool
$c== :: CreateResource -> CreateResource -> Bool
Prelude.Eq, ReadPrec [CreateResource]
ReadPrec CreateResource
Int -> ReadS CreateResource
ReadS [CreateResource]
(Int -> ReadS CreateResource)
-> ReadS [CreateResource]
-> ReadPrec CreateResource
-> ReadPrec [CreateResource]
-> Read CreateResource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateResource]
$creadListPrec :: ReadPrec [CreateResource]
readPrec :: ReadPrec CreateResource
$creadPrec :: ReadPrec CreateResource
readList :: ReadS [CreateResource]
$creadList :: ReadS [CreateResource]
readsPrec :: Int -> ReadS CreateResource
$creadsPrec :: Int -> ReadS CreateResource
Prelude.Read, Int -> CreateResource -> ShowS
[CreateResource] -> ShowS
CreateResource -> String
(Int -> CreateResource -> ShowS)
-> (CreateResource -> String)
-> ([CreateResource] -> ShowS)
-> Show CreateResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateResource] -> ShowS
$cshowList :: [CreateResource] -> ShowS
show :: CreateResource -> String
$cshow :: CreateResource -> String
showsPrec :: Int -> CreateResource -> ShowS
$cshowsPrec :: Int -> CreateResource -> ShowS
Prelude.Show, (forall x. CreateResource -> Rep CreateResource x)
-> (forall x. Rep CreateResource x -> CreateResource)
-> Generic CreateResource
forall x. Rep CreateResource x -> CreateResource
forall x. CreateResource -> Rep CreateResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateResource x -> CreateResource
$cfrom :: forall x. CreateResource -> Rep CreateResource x
Prelude.Generic)

-- |
-- Create a value of 'CreateResource' 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', 'createResource_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'parentId', 'createResource_parentId' - [Required] The parent resource\'s identifier.
--
-- 'pathPart', 'createResource_pathPart' - The last path segment for this resource.
newCreateResource ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'parentId'
  Prelude.Text ->
  -- | 'pathPart'
  Prelude.Text ->
  CreateResource
newCreateResource :: Text -> Text -> Text -> CreateResource
newCreateResource Text
pRestApiId_ Text
pParentId_ Text
pPathPart_ =
  CreateResource' :: Text -> Text -> Text -> CreateResource
CreateResource'
    { $sel:restApiId:CreateResource' :: Text
restApiId = Text
pRestApiId_,
      $sel:parentId:CreateResource' :: Text
parentId = Text
pParentId_,
      $sel:pathPart:CreateResource' :: Text
pathPart = Text
pPathPart_
    }

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

-- | [Required] The parent resource\'s identifier.
createResource_parentId :: Lens.Lens' CreateResource Prelude.Text
createResource_parentId :: (Text -> f Text) -> CreateResource -> f CreateResource
createResource_parentId = (CreateResource -> Text)
-> (CreateResource -> Text -> CreateResource)
-> Lens CreateResource CreateResource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResource' {Text
parentId :: Text
$sel:parentId:CreateResource' :: CreateResource -> Text
parentId} -> Text
parentId) (\s :: CreateResource
s@CreateResource' {} Text
a -> CreateResource
s {$sel:parentId:CreateResource' :: Text
parentId = Text
a} :: CreateResource)

-- | The last path segment for this resource.
createResource_pathPart :: Lens.Lens' CreateResource Prelude.Text
createResource_pathPart :: (Text -> f Text) -> CreateResource -> f CreateResource
createResource_pathPart = (CreateResource -> Text)
-> (CreateResource -> Text -> CreateResource)
-> Lens CreateResource CreateResource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResource' {Text
pathPart :: Text
$sel:pathPart:CreateResource' :: CreateResource -> Text
pathPart} -> Text
pathPart) (\s :: CreateResource
s@CreateResource' {} Text
a -> CreateResource
s {$sel:pathPart:CreateResource' :: Text
pathPart = Text
a} :: CreateResource)

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

instance Prelude.Hashable CreateResource

instance Prelude.NFData CreateResource

instance Core.ToHeaders CreateResource where
  toHeaders :: CreateResource -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateResource -> 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 CreateResource where
  toJSON :: CreateResource -> Value
toJSON CreateResource' {Text
pathPart :: Text
parentId :: Text
restApiId :: Text
$sel:pathPart:CreateResource' :: CreateResource -> Text
$sel:parentId:CreateResource' :: CreateResource -> Text
$sel:restApiId:CreateResource' :: CreateResource -> 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
"pathPart" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
pathPart)]
      )

instance Core.ToPath CreateResource where
  toPath :: CreateResource -> ByteString
toPath CreateResource' {Text
pathPart :: Text
parentId :: Text
restApiId :: Text
$sel:pathPart:CreateResource' :: CreateResource -> Text
$sel:parentId:CreateResource' :: CreateResource -> Text
$sel:restApiId:CreateResource' :: CreateResource -> 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
"/resources/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
parentId
      ]

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