{-# 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.IoT1ClickProjects.CreatePlacement
-- 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 an empty placement.
module Amazonka.IoT1ClickProjects.CreatePlacement
  ( -- * Creating a Request
    CreatePlacement (..),
    newCreatePlacement,

    -- * Request Lenses
    createPlacement_attributes,
    createPlacement_placementName,
    createPlacement_projectName,

    -- * Destructuring the Response
    CreatePlacementResponse (..),
    newCreatePlacementResponse,

    -- * Response Lenses
    createPlacementResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoT1ClickProjects.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:/ 'newCreatePlacement' smart constructor.
data CreatePlacement = CreatePlacement'
  { -- | Optional user-defined key\/value pairs providing contextual data (such
    -- as location or function) for the placement.
    CreatePlacement -> Maybe (HashMap Text Text)
attributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The name of the placement to be created.
    CreatePlacement -> Text
placementName :: Prelude.Text,
    -- | The name of the project in which to create the placement.
    CreatePlacement -> Text
projectName :: Prelude.Text
  }
  deriving (CreatePlacement -> CreatePlacement -> Bool
(CreatePlacement -> CreatePlacement -> Bool)
-> (CreatePlacement -> CreatePlacement -> Bool)
-> Eq CreatePlacement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreatePlacement -> CreatePlacement -> Bool
$c/= :: CreatePlacement -> CreatePlacement -> Bool
== :: CreatePlacement -> CreatePlacement -> Bool
$c== :: CreatePlacement -> CreatePlacement -> Bool
Prelude.Eq, ReadPrec [CreatePlacement]
ReadPrec CreatePlacement
Int -> ReadS CreatePlacement
ReadS [CreatePlacement]
(Int -> ReadS CreatePlacement)
-> ReadS [CreatePlacement]
-> ReadPrec CreatePlacement
-> ReadPrec [CreatePlacement]
-> Read CreatePlacement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreatePlacement]
$creadListPrec :: ReadPrec [CreatePlacement]
readPrec :: ReadPrec CreatePlacement
$creadPrec :: ReadPrec CreatePlacement
readList :: ReadS [CreatePlacement]
$creadList :: ReadS [CreatePlacement]
readsPrec :: Int -> ReadS CreatePlacement
$creadsPrec :: Int -> ReadS CreatePlacement
Prelude.Read, Int -> CreatePlacement -> ShowS
[CreatePlacement] -> ShowS
CreatePlacement -> String
(Int -> CreatePlacement -> ShowS)
-> (CreatePlacement -> String)
-> ([CreatePlacement] -> ShowS)
-> Show CreatePlacement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreatePlacement] -> ShowS
$cshowList :: [CreatePlacement] -> ShowS
show :: CreatePlacement -> String
$cshow :: CreatePlacement -> String
showsPrec :: Int -> CreatePlacement -> ShowS
$cshowsPrec :: Int -> CreatePlacement -> ShowS
Prelude.Show, (forall x. CreatePlacement -> Rep CreatePlacement x)
-> (forall x. Rep CreatePlacement x -> CreatePlacement)
-> Generic CreatePlacement
forall x. Rep CreatePlacement x -> CreatePlacement
forall x. CreatePlacement -> Rep CreatePlacement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreatePlacement x -> CreatePlacement
$cfrom :: forall x. CreatePlacement -> Rep CreatePlacement x
Prelude.Generic)

-- |
-- Create a value of 'CreatePlacement' 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:
--
-- 'attributes', 'createPlacement_attributes' - Optional user-defined key\/value pairs providing contextual data (such
-- as location or function) for the placement.
--
-- 'placementName', 'createPlacement_placementName' - The name of the placement to be created.
--
-- 'projectName', 'createPlacement_projectName' - The name of the project in which to create the placement.
newCreatePlacement ::
  -- | 'placementName'
  Prelude.Text ->
  -- | 'projectName'
  Prelude.Text ->
  CreatePlacement
newCreatePlacement :: Text -> Text -> CreatePlacement
newCreatePlacement Text
pPlacementName_ Text
pProjectName_ =
  CreatePlacement' :: Maybe (HashMap Text Text) -> Text -> Text -> CreatePlacement
CreatePlacement'
    { $sel:attributes:CreatePlacement' :: Maybe (HashMap Text Text)
attributes = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:placementName:CreatePlacement' :: Text
placementName = Text
pPlacementName_,
      $sel:projectName:CreatePlacement' :: Text
projectName = Text
pProjectName_
    }

-- | Optional user-defined key\/value pairs providing contextual data (such
-- as location or function) for the placement.
createPlacement_attributes :: Lens.Lens' CreatePlacement (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createPlacement_attributes :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreatePlacement -> f CreatePlacement
createPlacement_attributes = (CreatePlacement -> Maybe (HashMap Text Text))
-> (CreatePlacement
    -> Maybe (HashMap Text Text) -> CreatePlacement)
-> Lens
     CreatePlacement
     CreatePlacement
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePlacement' {Maybe (HashMap Text Text)
attributes :: Maybe (HashMap Text Text)
$sel:attributes:CreatePlacement' :: CreatePlacement -> Maybe (HashMap Text Text)
attributes} -> Maybe (HashMap Text Text)
attributes) (\s :: CreatePlacement
s@CreatePlacement' {} Maybe (HashMap Text Text)
a -> CreatePlacement
s {$sel:attributes:CreatePlacement' :: Maybe (HashMap Text Text)
attributes = Maybe (HashMap Text Text)
a} :: CreatePlacement) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> CreatePlacement -> f CreatePlacement)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreatePlacement
-> f CreatePlacement
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the placement to be created.
createPlacement_placementName :: Lens.Lens' CreatePlacement Prelude.Text
createPlacement_placementName :: (Text -> f Text) -> CreatePlacement -> f CreatePlacement
createPlacement_placementName = (CreatePlacement -> Text)
-> (CreatePlacement -> Text -> CreatePlacement)
-> Lens CreatePlacement CreatePlacement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePlacement' {Text
placementName :: Text
$sel:placementName:CreatePlacement' :: CreatePlacement -> Text
placementName} -> Text
placementName) (\s :: CreatePlacement
s@CreatePlacement' {} Text
a -> CreatePlacement
s {$sel:placementName:CreatePlacement' :: Text
placementName = Text
a} :: CreatePlacement)

-- | The name of the project in which to create the placement.
createPlacement_projectName :: Lens.Lens' CreatePlacement Prelude.Text
createPlacement_projectName :: (Text -> f Text) -> CreatePlacement -> f CreatePlacement
createPlacement_projectName = (CreatePlacement -> Text)
-> (CreatePlacement -> Text -> CreatePlacement)
-> Lens CreatePlacement CreatePlacement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePlacement' {Text
projectName :: Text
$sel:projectName:CreatePlacement' :: CreatePlacement -> Text
projectName} -> Text
projectName) (\s :: CreatePlacement
s@CreatePlacement' {} Text
a -> CreatePlacement
s {$sel:projectName:CreatePlacement' :: Text
projectName = Text
a} :: CreatePlacement)

instance Core.AWSRequest CreatePlacement where
  type
    AWSResponse CreatePlacement =
      CreatePlacementResponse
  request :: CreatePlacement -> Request CreatePlacement
request = Service -> CreatePlacement -> Request CreatePlacement
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreatePlacement
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreatePlacement)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreatePlacement))
-> Logger
-> Service
-> Proxy CreatePlacement
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreatePlacement)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> CreatePlacementResponse
CreatePlacementResponse'
            (Int -> CreatePlacementResponse)
-> Either String Int -> Either String CreatePlacementResponse
forall (f :: * -> *) a b. Functor 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 CreatePlacement

instance Prelude.NFData CreatePlacement

instance Core.ToHeaders CreatePlacement where
  toHeaders :: CreatePlacement -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreatePlacement -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 CreatePlacement where
  toJSON :: CreatePlacement -> Value
toJSON CreatePlacement' {Maybe (HashMap Text Text)
Text
projectName :: Text
placementName :: Text
attributes :: Maybe (HashMap Text Text)
$sel:projectName:CreatePlacement' :: CreatePlacement -> Text
$sel:placementName:CreatePlacement' :: CreatePlacement -> Text
$sel:attributes:CreatePlacement' :: CreatePlacement -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"attributes" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
attributes,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"placementName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
placementName)
          ]
      )

instance Core.ToPath CreatePlacement where
  toPath :: CreatePlacement -> ByteString
toPath CreatePlacement' {Maybe (HashMap Text Text)
Text
projectName :: Text
placementName :: Text
attributes :: Maybe (HashMap Text Text)
$sel:projectName:CreatePlacement' :: CreatePlacement -> Text
$sel:placementName:CreatePlacement' :: CreatePlacement -> Text
$sel:attributes:CreatePlacement' :: CreatePlacement -> Maybe (HashMap Text Text)
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/projects/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
projectName, ByteString
"/placements"]

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

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

-- |
-- Create a value of 'CreatePlacementResponse' 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:
--
-- 'httpStatus', 'createPlacementResponse_httpStatus' - The response's http status code.
newCreatePlacementResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreatePlacementResponse
newCreatePlacementResponse :: Int -> CreatePlacementResponse
newCreatePlacementResponse Int
pHttpStatus_ =
  CreatePlacementResponse' :: Int -> CreatePlacementResponse
CreatePlacementResponse' {$sel:httpStatus:CreatePlacementResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData CreatePlacementResponse