{-# 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.WorkSpaces.CreateConnectionAlias
-- 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 the specified connection alias for use with cross-Region
-- redirection. For more information, see
-- <https://docs.aws.amazon.com/workspaces/latest/adminguide/cross-region-redirection.html Cross-Region Redirection for Amazon WorkSpaces>.
module Amazonka.WorkSpaces.CreateConnectionAlias
  ( -- * Creating a Request
    CreateConnectionAlias (..),
    newCreateConnectionAlias,

    -- * Request Lenses
    createConnectionAlias_tags,
    createConnectionAlias_connectionString,

    -- * Destructuring the Response
    CreateConnectionAliasResponse (..),
    newCreateConnectionAliasResponse,

    -- * Response Lenses
    createConnectionAliasResponse_aliasId,
    createConnectionAliasResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateConnectionAlias' smart constructor.
data CreateConnectionAlias = CreateConnectionAlias'
  { -- | The tags to associate with the connection alias.
    CreateConnectionAlias -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | A connection string in the form of a fully qualified domain name (FQDN),
    -- such as @www.example.com@.
    --
    -- After you create a connection string, it is always associated to your
    -- Amazon Web Services account. You cannot recreate the same connection
    -- string with a different account, even if you delete all instances of it
    -- from the original account. The connection string is globally reserved
    -- for your account.
    CreateConnectionAlias -> Text
connectionString :: Prelude.Text
  }
  deriving (CreateConnectionAlias -> CreateConnectionAlias -> Bool
(CreateConnectionAlias -> CreateConnectionAlias -> Bool)
-> (CreateConnectionAlias -> CreateConnectionAlias -> Bool)
-> Eq CreateConnectionAlias
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateConnectionAlias -> CreateConnectionAlias -> Bool
$c/= :: CreateConnectionAlias -> CreateConnectionAlias -> Bool
== :: CreateConnectionAlias -> CreateConnectionAlias -> Bool
$c== :: CreateConnectionAlias -> CreateConnectionAlias -> Bool
Prelude.Eq, ReadPrec [CreateConnectionAlias]
ReadPrec CreateConnectionAlias
Int -> ReadS CreateConnectionAlias
ReadS [CreateConnectionAlias]
(Int -> ReadS CreateConnectionAlias)
-> ReadS [CreateConnectionAlias]
-> ReadPrec CreateConnectionAlias
-> ReadPrec [CreateConnectionAlias]
-> Read CreateConnectionAlias
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateConnectionAlias]
$creadListPrec :: ReadPrec [CreateConnectionAlias]
readPrec :: ReadPrec CreateConnectionAlias
$creadPrec :: ReadPrec CreateConnectionAlias
readList :: ReadS [CreateConnectionAlias]
$creadList :: ReadS [CreateConnectionAlias]
readsPrec :: Int -> ReadS CreateConnectionAlias
$creadsPrec :: Int -> ReadS CreateConnectionAlias
Prelude.Read, Int -> CreateConnectionAlias -> ShowS
[CreateConnectionAlias] -> ShowS
CreateConnectionAlias -> String
(Int -> CreateConnectionAlias -> ShowS)
-> (CreateConnectionAlias -> String)
-> ([CreateConnectionAlias] -> ShowS)
-> Show CreateConnectionAlias
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateConnectionAlias] -> ShowS
$cshowList :: [CreateConnectionAlias] -> ShowS
show :: CreateConnectionAlias -> String
$cshow :: CreateConnectionAlias -> String
showsPrec :: Int -> CreateConnectionAlias -> ShowS
$cshowsPrec :: Int -> CreateConnectionAlias -> ShowS
Prelude.Show, (forall x. CreateConnectionAlias -> Rep CreateConnectionAlias x)
-> (forall x. Rep CreateConnectionAlias x -> CreateConnectionAlias)
-> Generic CreateConnectionAlias
forall x. Rep CreateConnectionAlias x -> CreateConnectionAlias
forall x. CreateConnectionAlias -> Rep CreateConnectionAlias x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateConnectionAlias x -> CreateConnectionAlias
$cfrom :: forall x. CreateConnectionAlias -> Rep CreateConnectionAlias x
Prelude.Generic)

-- |
-- Create a value of 'CreateConnectionAlias' 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', 'createConnectionAlias_tags' - The tags to associate with the connection alias.
--
-- 'connectionString', 'createConnectionAlias_connectionString' - A connection string in the form of a fully qualified domain name (FQDN),
-- such as @www.example.com@.
--
-- After you create a connection string, it is always associated to your
-- Amazon Web Services account. You cannot recreate the same connection
-- string with a different account, even if you delete all instances of it
-- from the original account. The connection string is globally reserved
-- for your account.
newCreateConnectionAlias ::
  -- | 'connectionString'
  Prelude.Text ->
  CreateConnectionAlias
newCreateConnectionAlias :: Text -> CreateConnectionAlias
newCreateConnectionAlias Text
pConnectionString_ =
  CreateConnectionAlias' :: Maybe [Tag] -> Text -> CreateConnectionAlias
CreateConnectionAlias'
    { $sel:tags:CreateConnectionAlias' :: Maybe [Tag]
tags = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing,
      $sel:connectionString:CreateConnectionAlias' :: Text
connectionString = Text
pConnectionString_
    }

-- | The tags to associate with the connection alias.
createConnectionAlias_tags :: Lens.Lens' CreateConnectionAlias (Prelude.Maybe [Tag])
createConnectionAlias_tags :: (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateConnectionAlias -> f CreateConnectionAlias
createConnectionAlias_tags = (CreateConnectionAlias -> Maybe [Tag])
-> (CreateConnectionAlias -> Maybe [Tag] -> CreateConnectionAlias)
-> Lens
     CreateConnectionAlias
     CreateConnectionAlias
     (Maybe [Tag])
     (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnectionAlias' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateConnectionAlias' :: CreateConnectionAlias -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateConnectionAlias
s@CreateConnectionAlias' {} Maybe [Tag]
a -> CreateConnectionAlias
s {$sel:tags:CreateConnectionAlias' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateConnectionAlias) ((Maybe [Tag] -> f (Maybe [Tag]))
 -> CreateConnectionAlias -> f CreateConnectionAlias)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateConnectionAlias
-> f CreateConnectionAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
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 [Tag] [Tag] [Tag] [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A connection string in the form of a fully qualified domain name (FQDN),
-- such as @www.example.com@.
--
-- After you create a connection string, it is always associated to your
-- Amazon Web Services account. You cannot recreate the same connection
-- string with a different account, even if you delete all instances of it
-- from the original account. The connection string is globally reserved
-- for your account.
createConnectionAlias_connectionString :: Lens.Lens' CreateConnectionAlias Prelude.Text
createConnectionAlias_connectionString :: (Text -> f Text)
-> CreateConnectionAlias -> f CreateConnectionAlias
createConnectionAlias_connectionString = (CreateConnectionAlias -> Text)
-> (CreateConnectionAlias -> Text -> CreateConnectionAlias)
-> Lens CreateConnectionAlias CreateConnectionAlias Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnectionAlias' {Text
connectionString :: Text
$sel:connectionString:CreateConnectionAlias' :: CreateConnectionAlias -> Text
connectionString} -> Text
connectionString) (\s :: CreateConnectionAlias
s@CreateConnectionAlias' {} Text
a -> CreateConnectionAlias
s {$sel:connectionString:CreateConnectionAlias' :: Text
connectionString = Text
a} :: CreateConnectionAlias)

instance Core.AWSRequest CreateConnectionAlias where
  type
    AWSResponse CreateConnectionAlias =
      CreateConnectionAliasResponse
  request :: CreateConnectionAlias -> Request CreateConnectionAlias
request = Service -> CreateConnectionAlias -> Request CreateConnectionAlias
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateConnectionAlias
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateConnectionAlias)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateConnectionAlias))
-> Logger
-> Service
-> Proxy CreateConnectionAlias
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateConnectionAlias)))
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 ->
          Maybe Text -> Int -> CreateConnectionAliasResponse
CreateConnectionAliasResponse'
            (Maybe Text -> Int -> CreateConnectionAliasResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CreateConnectionAliasResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"AliasId")
            Either String (Int -> CreateConnectionAliasResponse)
-> Either String Int -> Either String CreateConnectionAliasResponse
forall (f :: * -> *) a b. Applicative f => 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 CreateConnectionAlias

instance Prelude.NFData CreateConnectionAlias

instance Core.ToHeaders CreateConnectionAlias where
  toHeaders :: CreateConnectionAlias -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateConnectionAlias -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"WorkspacesService.CreateConnectionAlias" ::
                          Prelude.ByteString
                      ),
            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 CreateConnectionAlias where
  toJSON :: CreateConnectionAlias -> Value
toJSON CreateConnectionAlias' {Maybe [Tag]
Text
connectionString :: Text
tags :: Maybe [Tag]
$sel:connectionString:CreateConnectionAlias' :: CreateConnectionAlias -> Text
$sel:tags:CreateConnectionAlias' :: CreateConnectionAlias -> Maybe [Tag]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Tags" Text -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Tag] -> Pair) -> Maybe [Tag] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ConnectionString" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
connectionString)
          ]
      )

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

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

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

-- |
-- Create a value of 'CreateConnectionAliasResponse' 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:
--
-- 'aliasId', 'createConnectionAliasResponse_aliasId' - The identifier of the connection alias.
--
-- 'httpStatus', 'createConnectionAliasResponse_httpStatus' - The response's http status code.
newCreateConnectionAliasResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateConnectionAliasResponse
newCreateConnectionAliasResponse :: Int -> CreateConnectionAliasResponse
newCreateConnectionAliasResponse Int
pHttpStatus_ =
  CreateConnectionAliasResponse' :: Maybe Text -> Int -> CreateConnectionAliasResponse
CreateConnectionAliasResponse'
    { $sel:aliasId:CreateConnectionAliasResponse' :: Maybe Text
aliasId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateConnectionAliasResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The identifier of the connection alias.
createConnectionAliasResponse_aliasId :: Lens.Lens' CreateConnectionAliasResponse (Prelude.Maybe Prelude.Text)
createConnectionAliasResponse_aliasId :: (Maybe Text -> f (Maybe Text))
-> CreateConnectionAliasResponse -> f CreateConnectionAliasResponse
createConnectionAliasResponse_aliasId = (CreateConnectionAliasResponse -> Maybe Text)
-> (CreateConnectionAliasResponse
    -> Maybe Text -> CreateConnectionAliasResponse)
-> Lens
     CreateConnectionAliasResponse
     CreateConnectionAliasResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnectionAliasResponse' {Maybe Text
aliasId :: Maybe Text
$sel:aliasId:CreateConnectionAliasResponse' :: CreateConnectionAliasResponse -> Maybe Text
aliasId} -> Maybe Text
aliasId) (\s :: CreateConnectionAliasResponse
s@CreateConnectionAliasResponse' {} Maybe Text
a -> CreateConnectionAliasResponse
s {$sel:aliasId:CreateConnectionAliasResponse' :: Maybe Text
aliasId = Maybe Text
a} :: CreateConnectionAliasResponse)

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

instance Prelude.NFData CreateConnectionAliasResponse