{-# 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.IVS.CreateStreamKey
-- 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 a stream key, used to initiate a stream, for the specified
-- channel ARN.
--
-- Note that CreateChannel creates a stream key. If you subsequently use
-- CreateStreamKey on the same channel, it will fail because a stream key
-- already exists and there is a limit of 1 stream key per channel. To
-- reset the stream key on a channel, use DeleteStreamKey and then
-- CreateStreamKey.
module Amazonka.IVS.CreateStreamKey
  ( -- * Creating a Request
    CreateStreamKey (..),
    newCreateStreamKey,

    -- * Request Lenses
    createStreamKey_tags,
    createStreamKey_channelArn,

    -- * Destructuring the Response
    CreateStreamKeyResponse (..),
    newCreateStreamKeyResponse,

    -- * Response Lenses
    createStreamKeyResponse_streamKey,
    createStreamKeyResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateStreamKey' smart constructor.
data CreateStreamKey = CreateStreamKey'
  { -- | Array of 1-50 maps, each of the form @string:string (key:value)@. See
    -- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services Resources>
    -- for more information, including restrictions that apply to tags and
    -- \"Tag naming limits and requirements\"; Amazon IVS has no
    -- service-specific constraints beyond what is documented there.
    CreateStreamKey -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | ARN of the channel for which to create the stream key.
    CreateStreamKey -> Text
channelArn :: Prelude.Text
  }
  deriving (CreateStreamKey -> CreateStreamKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateStreamKey -> CreateStreamKey -> Bool
$c/= :: CreateStreamKey -> CreateStreamKey -> Bool
== :: CreateStreamKey -> CreateStreamKey -> Bool
$c== :: CreateStreamKey -> CreateStreamKey -> Bool
Prelude.Eq, ReadPrec [CreateStreamKey]
ReadPrec CreateStreamKey
Int -> ReadS CreateStreamKey
ReadS [CreateStreamKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateStreamKey]
$creadListPrec :: ReadPrec [CreateStreamKey]
readPrec :: ReadPrec CreateStreamKey
$creadPrec :: ReadPrec CreateStreamKey
readList :: ReadS [CreateStreamKey]
$creadList :: ReadS [CreateStreamKey]
readsPrec :: Int -> ReadS CreateStreamKey
$creadsPrec :: Int -> ReadS CreateStreamKey
Prelude.Read, Int -> CreateStreamKey -> ShowS
[CreateStreamKey] -> ShowS
CreateStreamKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateStreamKey] -> ShowS
$cshowList :: [CreateStreamKey] -> ShowS
show :: CreateStreamKey -> String
$cshow :: CreateStreamKey -> String
showsPrec :: Int -> CreateStreamKey -> ShowS
$cshowsPrec :: Int -> CreateStreamKey -> ShowS
Prelude.Show, forall x. Rep CreateStreamKey x -> CreateStreamKey
forall x. CreateStreamKey -> Rep CreateStreamKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateStreamKey x -> CreateStreamKey
$cfrom :: forall x. CreateStreamKey -> Rep CreateStreamKey x
Prelude.Generic)

-- |
-- Create a value of 'CreateStreamKey' 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', 'createStreamKey_tags' - Array of 1-50 maps, each of the form @string:string (key:value)@. See
-- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services Resources>
-- for more information, including restrictions that apply to tags and
-- \"Tag naming limits and requirements\"; Amazon IVS has no
-- service-specific constraints beyond what is documented there.
--
-- 'channelArn', 'createStreamKey_channelArn' - ARN of the channel for which to create the stream key.
newCreateStreamKey ::
  -- | 'channelArn'
  Prelude.Text ->
  CreateStreamKey
newCreateStreamKey :: Text -> CreateStreamKey
newCreateStreamKey Text
pChannelArn_ =
  CreateStreamKey'
    { $sel:tags:CreateStreamKey' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:channelArn:CreateStreamKey' :: Text
channelArn = Text
pChannelArn_
    }

-- | Array of 1-50 maps, each of the form @string:string (key:value)@. See
-- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services Resources>
-- for more information, including restrictions that apply to tags and
-- \"Tag naming limits and requirements\"; Amazon IVS has no
-- service-specific constraints beyond what is documented there.
createStreamKey_tags :: Lens.Lens' CreateStreamKey (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createStreamKey_tags :: Lens' CreateStreamKey (Maybe (HashMap Text Text))
createStreamKey_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateStreamKey' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateStreamKey' :: CreateStreamKey -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateStreamKey
s@CreateStreamKey' {} Maybe (HashMap Text Text)
a -> CreateStreamKey
s {$sel:tags:CreateStreamKey' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateStreamKey) 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

-- | ARN of the channel for which to create the stream key.
createStreamKey_channelArn :: Lens.Lens' CreateStreamKey Prelude.Text
createStreamKey_channelArn :: Lens' CreateStreamKey Text
createStreamKey_channelArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateStreamKey' {Text
channelArn :: Text
$sel:channelArn:CreateStreamKey' :: CreateStreamKey -> Text
channelArn} -> Text
channelArn) (\s :: CreateStreamKey
s@CreateStreamKey' {} Text
a -> CreateStreamKey
s {$sel:channelArn:CreateStreamKey' :: Text
channelArn = Text
a} :: CreateStreamKey)

instance Core.AWSRequest CreateStreamKey where
  type
    AWSResponse CreateStreamKey =
      CreateStreamKeyResponse
  request :: (Service -> Service) -> CreateStreamKey -> Request CreateStreamKey
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 CreateStreamKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateStreamKey)))
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 StreamKey -> Int -> CreateStreamKeyResponse
CreateStreamKeyResponse'
            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
"streamKey")
            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 CreateStreamKey where
  hashWithSalt :: Int -> CreateStreamKey -> Int
hashWithSalt Int
_salt CreateStreamKey' {Maybe (HashMap Text Text)
Text
channelArn :: Text
tags :: Maybe (HashMap Text Text)
$sel:channelArn:CreateStreamKey' :: CreateStreamKey -> Text
$sel:tags:CreateStreamKey' :: CreateStreamKey -> Maybe (HashMap Text Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
channelArn

instance Prelude.NFData CreateStreamKey where
  rnf :: CreateStreamKey -> ()
rnf CreateStreamKey' {Maybe (HashMap Text Text)
Text
channelArn :: Text
tags :: Maybe (HashMap Text Text)
$sel:channelArn:CreateStreamKey' :: CreateStreamKey -> Text
$sel:tags:CreateStreamKey' :: CreateStreamKey -> Maybe (HashMap Text Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
channelArn

instance Data.ToHeaders CreateStreamKey where
  toHeaders :: CreateStreamKey -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateStreamKey where
  toJSON :: CreateStreamKey -> Value
toJSON CreateStreamKey' {Maybe (HashMap Text Text)
Text
channelArn :: Text
tags :: Maybe (HashMap Text Text)
$sel:channelArn:CreateStreamKey' :: CreateStreamKey -> Text
$sel:tags:CreateStreamKey' :: CreateStreamKey -> Maybe (HashMap Text Text)
..} =
    [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 (HashMap Text Text)
tags,
            forall a. a -> Maybe a
Prelude.Just (Key
"channelArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
channelArn)
          ]
      )

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

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

-- | /See:/ 'newCreateStreamKeyResponse' smart constructor.
data CreateStreamKeyResponse = CreateStreamKeyResponse'
  { -- | Stream key used to authenticate an RTMPS stream for ingestion.
    CreateStreamKeyResponse -> Maybe StreamKey
streamKey :: Prelude.Maybe StreamKey,
    -- | The response's http status code.
    CreateStreamKeyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool
$c/= :: CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool
== :: CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool
$c== :: CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool
Prelude.Eq, Int -> CreateStreamKeyResponse -> ShowS
[CreateStreamKeyResponse] -> ShowS
CreateStreamKeyResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateStreamKeyResponse] -> ShowS
$cshowList :: [CreateStreamKeyResponse] -> ShowS
show :: CreateStreamKeyResponse -> String
$cshow :: CreateStreamKeyResponse -> String
showsPrec :: Int -> CreateStreamKeyResponse -> ShowS
$cshowsPrec :: Int -> CreateStreamKeyResponse -> ShowS
Prelude.Show, forall x. Rep CreateStreamKeyResponse x -> CreateStreamKeyResponse
forall x. CreateStreamKeyResponse -> Rep CreateStreamKeyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateStreamKeyResponse x -> CreateStreamKeyResponse
$cfrom :: forall x. CreateStreamKeyResponse -> Rep CreateStreamKeyResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateStreamKeyResponse' 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:
--
-- 'streamKey', 'createStreamKeyResponse_streamKey' - Stream key used to authenticate an RTMPS stream for ingestion.
--
-- 'httpStatus', 'createStreamKeyResponse_httpStatus' - The response's http status code.
newCreateStreamKeyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateStreamKeyResponse
newCreateStreamKeyResponse :: Int -> CreateStreamKeyResponse
newCreateStreamKeyResponse Int
pHttpStatus_ =
  CreateStreamKeyResponse'
    { $sel:streamKey:CreateStreamKeyResponse' :: Maybe StreamKey
streamKey =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateStreamKeyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Stream key used to authenticate an RTMPS stream for ingestion.
createStreamKeyResponse_streamKey :: Lens.Lens' CreateStreamKeyResponse (Prelude.Maybe StreamKey)
createStreamKeyResponse_streamKey :: Lens' CreateStreamKeyResponse (Maybe StreamKey)
createStreamKeyResponse_streamKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateStreamKeyResponse' {Maybe StreamKey
streamKey :: Maybe StreamKey
$sel:streamKey:CreateStreamKeyResponse' :: CreateStreamKeyResponse -> Maybe StreamKey
streamKey} -> Maybe StreamKey
streamKey) (\s :: CreateStreamKeyResponse
s@CreateStreamKeyResponse' {} Maybe StreamKey
a -> CreateStreamKeyResponse
s {$sel:streamKey:CreateStreamKeyResponse' :: Maybe StreamKey
streamKey = Maybe StreamKey
a} :: CreateStreamKeyResponse)

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

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