{-# 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.ChimeSDKIdentity.CreateAppInstance
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates an Amazon Chime SDK messaging @AppInstance@ under an AWS
-- account. Only SDK messaging customers use this API. @CreateAppInstance@
-- supports idempotency behavior as described in the AWS API Standard.
--
-- identity
module Amazonka.ChimeSDKIdentity.CreateAppInstance
  ( -- * Creating a Request
    CreateAppInstance (..),
    newCreateAppInstance,

    -- * Request Lenses
    createAppInstance_metadata,
    createAppInstance_tags,
    createAppInstance_name,
    createAppInstance_clientRequestToken,

    -- * Destructuring the Response
    CreateAppInstanceResponse (..),
    newCreateAppInstanceResponse,

    -- * Response Lenses
    createAppInstanceResponse_appInstanceArn,
    createAppInstanceResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateAppInstance' smart constructor.
data CreateAppInstance = CreateAppInstance'
  { -- | The metadata of the @AppInstance@. Limited to a 1KB string in UTF-8.
    CreateAppInstance -> Maybe (Sensitive Text)
metadata :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | Tags assigned to the @AppInstanceUser@.
    CreateAppInstance -> Maybe (NonEmpty Tag)
tags :: Prelude.Maybe (Prelude.NonEmpty Tag),
    -- | The name of the @AppInstance@.
    CreateAppInstance -> Sensitive Text
name :: Data.Sensitive Prelude.Text,
    -- | The @ClientRequestToken@ of the @AppInstance@.
    CreateAppInstance -> Sensitive Text
clientRequestToken :: Data.Sensitive Prelude.Text
  }
  deriving (CreateAppInstance -> CreateAppInstance -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateAppInstance -> CreateAppInstance -> Bool
$c/= :: CreateAppInstance -> CreateAppInstance -> Bool
== :: CreateAppInstance -> CreateAppInstance -> Bool
$c== :: CreateAppInstance -> CreateAppInstance -> Bool
Prelude.Eq, Int -> CreateAppInstance -> ShowS
[CreateAppInstance] -> ShowS
CreateAppInstance -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateAppInstance] -> ShowS
$cshowList :: [CreateAppInstance] -> ShowS
show :: CreateAppInstance -> String
$cshow :: CreateAppInstance -> String
showsPrec :: Int -> CreateAppInstance -> ShowS
$cshowsPrec :: Int -> CreateAppInstance -> ShowS
Prelude.Show, forall x. Rep CreateAppInstance x -> CreateAppInstance
forall x. CreateAppInstance -> Rep CreateAppInstance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateAppInstance x -> CreateAppInstance
$cfrom :: forall x. CreateAppInstance -> Rep CreateAppInstance x
Prelude.Generic)

-- |
-- Create a value of 'CreateAppInstance' 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:
--
-- 'metadata', 'createAppInstance_metadata' - The metadata of the @AppInstance@. Limited to a 1KB string in UTF-8.
--
-- 'tags', 'createAppInstance_tags' - Tags assigned to the @AppInstanceUser@.
--
-- 'name', 'createAppInstance_name' - The name of the @AppInstance@.
--
-- 'clientRequestToken', 'createAppInstance_clientRequestToken' - The @ClientRequestToken@ of the @AppInstance@.
newCreateAppInstance ::
  -- | 'name'
  Prelude.Text ->
  -- | 'clientRequestToken'
  Prelude.Text ->
  CreateAppInstance
newCreateAppInstance :: Text -> Text -> CreateAppInstance
newCreateAppInstance Text
pName_ Text
pClientRequestToken_ =
  CreateAppInstance'
    { $sel:metadata:CreateAppInstance' :: Maybe (Sensitive Text)
metadata = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateAppInstance' :: Maybe (NonEmpty Tag)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:name:CreateAppInstance' :: Sensitive Text
name = forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pName_,
      $sel:clientRequestToken:CreateAppInstance' :: Sensitive Text
clientRequestToken =
        forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pClientRequestToken_
    }

-- | The metadata of the @AppInstance@. Limited to a 1KB string in UTF-8.
createAppInstance_metadata :: Lens.Lens' CreateAppInstance (Prelude.Maybe Prelude.Text)
createAppInstance_metadata :: Lens' CreateAppInstance (Maybe Text)
createAppInstance_metadata = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAppInstance' {Maybe (Sensitive Text)
metadata :: Maybe (Sensitive Text)
$sel:metadata:CreateAppInstance' :: CreateAppInstance -> Maybe (Sensitive Text)
metadata} -> Maybe (Sensitive Text)
metadata) (\s :: CreateAppInstance
s@CreateAppInstance' {} Maybe (Sensitive Text)
a -> CreateAppInstance
s {$sel:metadata:CreateAppInstance' :: Maybe (Sensitive Text)
metadata = Maybe (Sensitive Text)
a} :: CreateAppInstance) 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 a. Iso' (Sensitive a) a
Data._Sensitive

-- | Tags assigned to the @AppInstanceUser@.
createAppInstance_tags :: Lens.Lens' CreateAppInstance (Prelude.Maybe (Prelude.NonEmpty Tag))
createAppInstance_tags :: Lens' CreateAppInstance (Maybe (NonEmpty Tag))
createAppInstance_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAppInstance' {Maybe (NonEmpty Tag)
tags :: Maybe (NonEmpty Tag)
$sel:tags:CreateAppInstance' :: CreateAppInstance -> Maybe (NonEmpty Tag)
tags} -> Maybe (NonEmpty Tag)
tags) (\s :: CreateAppInstance
s@CreateAppInstance' {} Maybe (NonEmpty Tag)
a -> CreateAppInstance
s {$sel:tags:CreateAppInstance' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
a} :: CreateAppInstance) 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 @AppInstance@.
createAppInstance_name :: Lens.Lens' CreateAppInstance Prelude.Text
createAppInstance_name :: Lens' CreateAppInstance Text
createAppInstance_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAppInstance' {Sensitive Text
name :: Sensitive Text
$sel:name:CreateAppInstance' :: CreateAppInstance -> Sensitive Text
name} -> Sensitive Text
name) (\s :: CreateAppInstance
s@CreateAppInstance' {} Sensitive Text
a -> CreateAppInstance
s {$sel:name:CreateAppInstance' :: Sensitive Text
name = Sensitive Text
a} :: CreateAppInstance) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The @ClientRequestToken@ of the @AppInstance@.
createAppInstance_clientRequestToken :: Lens.Lens' CreateAppInstance Prelude.Text
createAppInstance_clientRequestToken :: Lens' CreateAppInstance Text
createAppInstance_clientRequestToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAppInstance' {Sensitive Text
clientRequestToken :: Sensitive Text
$sel:clientRequestToken:CreateAppInstance' :: CreateAppInstance -> Sensitive Text
clientRequestToken} -> Sensitive Text
clientRequestToken) (\s :: CreateAppInstance
s@CreateAppInstance' {} Sensitive Text
a -> CreateAppInstance
s {$sel:clientRequestToken:CreateAppInstance' :: Sensitive Text
clientRequestToken = Sensitive Text
a} :: CreateAppInstance) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Core.AWSRequest CreateAppInstance where
  type
    AWSResponse CreateAppInstance =
      CreateAppInstanceResponse
  request :: (Service -> Service)
-> CreateAppInstance -> Request CreateAppInstance
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 CreateAppInstance
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateAppInstance)))
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 ->
          Maybe Text -> Int -> CreateAppInstanceResponse
CreateAppInstanceResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"AppInstanceArn")
            forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable CreateAppInstance where
  hashWithSalt :: Int -> CreateAppInstance -> Int
hashWithSalt Int
_salt CreateAppInstance' {Maybe (NonEmpty Tag)
Maybe (Sensitive Text)
Sensitive Text
clientRequestToken :: Sensitive Text
name :: Sensitive Text
tags :: Maybe (NonEmpty Tag)
metadata :: Maybe (Sensitive Text)
$sel:clientRequestToken:CreateAppInstance' :: CreateAppInstance -> Sensitive Text
$sel:name:CreateAppInstance' :: CreateAppInstance -> Sensitive Text
$sel:tags:CreateAppInstance' :: CreateAppInstance -> Maybe (NonEmpty Tag)
$sel:metadata:CreateAppInstance' :: CreateAppInstance -> Maybe (Sensitive Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
metadata
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Tag)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
clientRequestToken

instance Prelude.NFData CreateAppInstance where
  rnf :: CreateAppInstance -> ()
rnf CreateAppInstance' {Maybe (NonEmpty Tag)
Maybe (Sensitive Text)
Sensitive Text
clientRequestToken :: Sensitive Text
name :: Sensitive Text
tags :: Maybe (NonEmpty Tag)
metadata :: Maybe (Sensitive Text)
$sel:clientRequestToken:CreateAppInstance' :: CreateAppInstance -> Sensitive Text
$sel:name:CreateAppInstance' :: CreateAppInstance -> Sensitive Text
$sel:tags:CreateAppInstance' :: CreateAppInstance -> Maybe (NonEmpty Tag)
$sel:metadata:CreateAppInstance' :: CreateAppInstance -> Maybe (Sensitive Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
metadata
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 Sensitive Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
clientRequestToken

instance Data.ToHeaders CreateAppInstance where
  toHeaders :: CreateAppInstance -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

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

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

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

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

-- |
-- Create a value of 'CreateAppInstanceResponse' 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:
--
-- 'appInstanceArn', 'createAppInstanceResponse_appInstanceArn' - The Amazon Resource Number (ARN) of the @AppInstance@.
--
-- 'httpStatus', 'createAppInstanceResponse_httpStatus' - The response's http status code.
newCreateAppInstanceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateAppInstanceResponse
newCreateAppInstanceResponse :: Int -> CreateAppInstanceResponse
newCreateAppInstanceResponse Int
pHttpStatus_ =
  CreateAppInstanceResponse'
    { $sel:appInstanceArn:CreateAppInstanceResponse' :: Maybe Text
appInstanceArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateAppInstanceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Number (ARN) of the @AppInstance@.
createAppInstanceResponse_appInstanceArn :: Lens.Lens' CreateAppInstanceResponse (Prelude.Maybe Prelude.Text)
createAppInstanceResponse_appInstanceArn :: Lens' CreateAppInstanceResponse (Maybe Text)
createAppInstanceResponse_appInstanceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAppInstanceResponse' {Maybe Text
appInstanceArn :: Maybe Text
$sel:appInstanceArn:CreateAppInstanceResponse' :: CreateAppInstanceResponse -> Maybe Text
appInstanceArn} -> Maybe Text
appInstanceArn) (\s :: CreateAppInstanceResponse
s@CreateAppInstanceResponse' {} Maybe Text
a -> CreateAppInstanceResponse
s {$sel:appInstanceArn:CreateAppInstanceResponse' :: Maybe Text
appInstanceArn = Maybe Text
a} :: CreateAppInstanceResponse)

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

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