{-# 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.KeySpaces.CreateKeyspace
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- The @CreateKeyspace@ operation adds a new keyspace to your account. In
-- an Amazon Web Services account, keyspace names must be unique within
-- each Region.
--
-- @CreateKeyspace@ is an asynchronous operation. You can monitor the
-- creation status of the new keyspace by using the @GetKeyspace@
-- operation.
--
-- For more information, see
-- <https://docs.aws.amazon.com/keyspaces/latest/devguide/working-with-keyspaces.html#keyspaces-create Creating keyspaces>
-- in the /Amazon Keyspaces Developer Guide/.
module Amazonka.KeySpaces.CreateKeyspace
  ( -- * Creating a Request
    CreateKeyspace (..),
    newCreateKeyspace,

    -- * Request Lenses
    createKeyspace_tags,
    createKeyspace_keyspaceName,

    -- * Destructuring the Response
    CreateKeyspaceResponse (..),
    newCreateKeyspaceResponse,

    -- * Response Lenses
    createKeyspaceResponse_httpStatus,
    createKeyspaceResponse_resourceArn,
  )
where

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

-- | /See:/ 'newCreateKeyspace' smart constructor.
data CreateKeyspace = CreateKeyspace'
  { -- | A list of key-value pair tags to be attached to the keyspace.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/keyspaces/latest/devguide/tagging-keyspaces.html Adding tags and labels to Amazon Keyspaces resources>
    -- in the /Amazon Keyspaces Developer Guide/.
    CreateKeyspace -> Maybe (NonEmpty Tag)
tags :: Prelude.Maybe (Prelude.NonEmpty Tag),
    -- | The name of the keyspace to be created.
    CreateKeyspace -> Text
keyspaceName :: Prelude.Text
  }
  deriving (CreateKeyspace -> CreateKeyspace -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateKeyspace -> CreateKeyspace -> Bool
$c/= :: CreateKeyspace -> CreateKeyspace -> Bool
== :: CreateKeyspace -> CreateKeyspace -> Bool
$c== :: CreateKeyspace -> CreateKeyspace -> Bool
Prelude.Eq, ReadPrec [CreateKeyspace]
ReadPrec CreateKeyspace
Int -> ReadS CreateKeyspace
ReadS [CreateKeyspace]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateKeyspace]
$creadListPrec :: ReadPrec [CreateKeyspace]
readPrec :: ReadPrec CreateKeyspace
$creadPrec :: ReadPrec CreateKeyspace
readList :: ReadS [CreateKeyspace]
$creadList :: ReadS [CreateKeyspace]
readsPrec :: Int -> ReadS CreateKeyspace
$creadsPrec :: Int -> ReadS CreateKeyspace
Prelude.Read, Int -> CreateKeyspace -> ShowS
[CreateKeyspace] -> ShowS
CreateKeyspace -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateKeyspace] -> ShowS
$cshowList :: [CreateKeyspace] -> ShowS
show :: CreateKeyspace -> String
$cshow :: CreateKeyspace -> String
showsPrec :: Int -> CreateKeyspace -> ShowS
$cshowsPrec :: Int -> CreateKeyspace -> ShowS
Prelude.Show, forall x. Rep CreateKeyspace x -> CreateKeyspace
forall x. CreateKeyspace -> Rep CreateKeyspace x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateKeyspace x -> CreateKeyspace
$cfrom :: forall x. CreateKeyspace -> Rep CreateKeyspace x
Prelude.Generic)

-- |
-- Create a value of 'CreateKeyspace' 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:
--
-- 'tags', 'createKeyspace_tags' - A list of key-value pair tags to be attached to the keyspace.
--
-- For more information, see
-- <https://docs.aws.amazon.com/keyspaces/latest/devguide/tagging-keyspaces.html Adding tags and labels to Amazon Keyspaces resources>
-- in the /Amazon Keyspaces Developer Guide/.
--
-- 'keyspaceName', 'createKeyspace_keyspaceName' - The name of the keyspace to be created.
newCreateKeyspace ::
  -- | 'keyspaceName'
  Prelude.Text ->
  CreateKeyspace
newCreateKeyspace :: Text -> CreateKeyspace
newCreateKeyspace Text
pKeyspaceName_ =
  CreateKeyspace'
    { $sel:tags:CreateKeyspace' :: Maybe (NonEmpty Tag)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:keyspaceName:CreateKeyspace' :: Text
keyspaceName = Text
pKeyspaceName_
    }

-- | A list of key-value pair tags to be attached to the keyspace.
--
-- For more information, see
-- <https://docs.aws.amazon.com/keyspaces/latest/devguide/tagging-keyspaces.html Adding tags and labels to Amazon Keyspaces resources>
-- in the /Amazon Keyspaces Developer Guide/.
createKeyspace_tags :: Lens.Lens' CreateKeyspace (Prelude.Maybe (Prelude.NonEmpty Tag))
createKeyspace_tags :: Lens' CreateKeyspace (Maybe (NonEmpty Tag))
createKeyspace_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateKeyspace' {Maybe (NonEmpty Tag)
tags :: Maybe (NonEmpty Tag)
$sel:tags:CreateKeyspace' :: CreateKeyspace -> Maybe (NonEmpty Tag)
tags} -> Maybe (NonEmpty Tag)
tags) (\s :: CreateKeyspace
s@CreateKeyspace' {} Maybe (NonEmpty Tag)
a -> CreateKeyspace
s {$sel:tags:CreateKeyspace' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
a} :: CreateKeyspace) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the keyspace to be created.
createKeyspace_keyspaceName :: Lens.Lens' CreateKeyspace Prelude.Text
createKeyspace_keyspaceName :: Lens' CreateKeyspace Text
createKeyspace_keyspaceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateKeyspace' {Text
keyspaceName :: Text
$sel:keyspaceName:CreateKeyspace' :: CreateKeyspace -> Text
keyspaceName} -> Text
keyspaceName) (\s :: CreateKeyspace
s@CreateKeyspace' {} Text
a -> CreateKeyspace
s {$sel:keyspaceName:CreateKeyspace' :: Text
keyspaceName = Text
a} :: CreateKeyspace)

instance Core.AWSRequest CreateKeyspace where
  type
    AWSResponse CreateKeyspace =
      CreateKeyspaceResponse
  request :: (Service -> Service) -> CreateKeyspace -> Request CreateKeyspace
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 CreateKeyspace
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateKeyspace)))
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 ->
          Int -> Text -> CreateKeyspaceResponse
CreateKeyspaceResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"resourceArn")
      )

instance Prelude.Hashable CreateKeyspace where
  hashWithSalt :: Int -> CreateKeyspace -> Int
hashWithSalt Int
_salt CreateKeyspace' {Maybe (NonEmpty Tag)
Text
keyspaceName :: Text
tags :: Maybe (NonEmpty Tag)
$sel:keyspaceName:CreateKeyspace' :: CreateKeyspace -> Text
$sel:tags:CreateKeyspace' :: CreateKeyspace -> Maybe (NonEmpty Tag)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Tag)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
keyspaceName

instance Prelude.NFData CreateKeyspace where
  rnf :: CreateKeyspace -> ()
rnf CreateKeyspace' {Maybe (NonEmpty Tag)
Text
keyspaceName :: Text
tags :: Maybe (NonEmpty Tag)
$sel:keyspaceName:CreateKeyspace' :: CreateKeyspace -> Text
$sel:tags:CreateKeyspace' :: CreateKeyspace -> Maybe (NonEmpty Tag)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Tag)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
keyspaceName

instance Data.ToHeaders CreateKeyspace where
  toHeaders :: CreateKeyspace -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"KeyspacesService.CreateKeyspace" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateKeyspace where
  toJSON :: CreateKeyspace -> Value
toJSON CreateKeyspace' {Maybe (NonEmpty Tag)
Text
keyspaceName :: Text
tags :: Maybe (NonEmpty Tag)
$sel:keyspaceName:CreateKeyspace' :: CreateKeyspace -> Text
$sel:tags:CreateKeyspace' :: CreateKeyspace -> Maybe (NonEmpty Tag)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"tags" 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 (NonEmpty Tag)
tags,
            forall a. a -> Maybe a
Prelude.Just (Key
"keyspaceName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
keyspaceName)
          ]
      )

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

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

-- | /See:/ 'newCreateKeyspaceResponse' smart constructor.
data CreateKeyspaceResponse = CreateKeyspaceResponse'
  { -- | The response's http status code.
    CreateKeyspaceResponse -> Int
httpStatus :: Prelude.Int,
    -- | The unique identifier of the keyspace in the format of an Amazon
    -- Resource Name (ARN).
    CreateKeyspaceResponse -> Text
resourceArn :: Prelude.Text
  }
  deriving (CreateKeyspaceResponse -> CreateKeyspaceResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateKeyspaceResponse -> CreateKeyspaceResponse -> Bool
$c/= :: CreateKeyspaceResponse -> CreateKeyspaceResponse -> Bool
== :: CreateKeyspaceResponse -> CreateKeyspaceResponse -> Bool
$c== :: CreateKeyspaceResponse -> CreateKeyspaceResponse -> Bool
Prelude.Eq, ReadPrec [CreateKeyspaceResponse]
ReadPrec CreateKeyspaceResponse
Int -> ReadS CreateKeyspaceResponse
ReadS [CreateKeyspaceResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateKeyspaceResponse]
$creadListPrec :: ReadPrec [CreateKeyspaceResponse]
readPrec :: ReadPrec CreateKeyspaceResponse
$creadPrec :: ReadPrec CreateKeyspaceResponse
readList :: ReadS [CreateKeyspaceResponse]
$creadList :: ReadS [CreateKeyspaceResponse]
readsPrec :: Int -> ReadS CreateKeyspaceResponse
$creadsPrec :: Int -> ReadS CreateKeyspaceResponse
Prelude.Read, Int -> CreateKeyspaceResponse -> ShowS
[CreateKeyspaceResponse] -> ShowS
CreateKeyspaceResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateKeyspaceResponse] -> ShowS
$cshowList :: [CreateKeyspaceResponse] -> ShowS
show :: CreateKeyspaceResponse -> String
$cshow :: CreateKeyspaceResponse -> String
showsPrec :: Int -> CreateKeyspaceResponse -> ShowS
$cshowsPrec :: Int -> CreateKeyspaceResponse -> ShowS
Prelude.Show, forall x. Rep CreateKeyspaceResponse x -> CreateKeyspaceResponse
forall x. CreateKeyspaceResponse -> Rep CreateKeyspaceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateKeyspaceResponse x -> CreateKeyspaceResponse
$cfrom :: forall x. CreateKeyspaceResponse -> Rep CreateKeyspaceResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateKeyspaceResponse' 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', 'createKeyspaceResponse_httpStatus' - The response's http status code.
--
-- 'resourceArn', 'createKeyspaceResponse_resourceArn' - The unique identifier of the keyspace in the format of an Amazon
-- Resource Name (ARN).
newCreateKeyspaceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'resourceArn'
  Prelude.Text ->
  CreateKeyspaceResponse
newCreateKeyspaceResponse :: Int -> Text -> CreateKeyspaceResponse
newCreateKeyspaceResponse Int
pHttpStatus_ Text
pResourceArn_ =
  CreateKeyspaceResponse'
    { $sel:httpStatus:CreateKeyspaceResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:resourceArn:CreateKeyspaceResponse' :: Text
resourceArn = Text
pResourceArn_
    }

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

-- | The unique identifier of the keyspace in the format of an Amazon
-- Resource Name (ARN).
createKeyspaceResponse_resourceArn :: Lens.Lens' CreateKeyspaceResponse Prelude.Text
createKeyspaceResponse_resourceArn :: Lens' CreateKeyspaceResponse Text
createKeyspaceResponse_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateKeyspaceResponse' {Text
resourceArn :: Text
$sel:resourceArn:CreateKeyspaceResponse' :: CreateKeyspaceResponse -> Text
resourceArn} -> Text
resourceArn) (\s :: CreateKeyspaceResponse
s@CreateKeyspaceResponse' {} Text
a -> CreateKeyspaceResponse
s {$sel:resourceArn:CreateKeyspaceResponse' :: Text
resourceArn = Text
a} :: CreateKeyspaceResponse)

instance Prelude.NFData CreateKeyspaceResponse where
  rnf :: CreateKeyspaceResponse -> ()
rnf CreateKeyspaceResponse' {Int
Text
resourceArn :: Text
httpStatus :: Int
$sel:resourceArn:CreateKeyspaceResponse' :: CreateKeyspaceResponse -> Text
$sel:httpStatus:CreateKeyspaceResponse' :: CreateKeyspaceResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
resourceArn