{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CognitoSync.Types.CognitoStreams
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CognitoSync.Types.CognitoStreams where

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

-- | Configuration options for configure Cognito streams.
--
-- /See:/ 'newCognitoStreams' smart constructor.
data CognitoStreams = CognitoStreams'
  { -- | The ARN of the role Amazon Cognito can assume in order to publish to the
    -- stream. This role must grant access to Amazon Cognito (cognito-sync) to
    -- invoke PutRecord on your Cognito stream.
    CognitoStreams -> Maybe Text
roleArn :: Prelude.Maybe Prelude.Text,
    -- | The name of the Cognito stream to receive updates. This stream must be
    -- in the developers account and in the same region as the identity pool.
    CognitoStreams -> Maybe Text
streamName :: Prelude.Maybe Prelude.Text,
    -- | Status of the Cognito streams. Valid values are:
    --
    -- ENABLED - Streaming of updates to identity pool is enabled.
    --
    -- DISABLED - Streaming of updates to identity pool is disabled. Bulk
    -- publish will also fail if StreamingStatus is DISABLED.
    CognitoStreams -> Maybe StreamingStatus
streamingStatus :: Prelude.Maybe StreamingStatus
  }
  deriving (CognitoStreams -> CognitoStreams -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CognitoStreams -> CognitoStreams -> Bool
$c/= :: CognitoStreams -> CognitoStreams -> Bool
== :: CognitoStreams -> CognitoStreams -> Bool
$c== :: CognitoStreams -> CognitoStreams -> Bool
Prelude.Eq, ReadPrec [CognitoStreams]
ReadPrec CognitoStreams
Int -> ReadS CognitoStreams
ReadS [CognitoStreams]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CognitoStreams]
$creadListPrec :: ReadPrec [CognitoStreams]
readPrec :: ReadPrec CognitoStreams
$creadPrec :: ReadPrec CognitoStreams
readList :: ReadS [CognitoStreams]
$creadList :: ReadS [CognitoStreams]
readsPrec :: Int -> ReadS CognitoStreams
$creadsPrec :: Int -> ReadS CognitoStreams
Prelude.Read, Int -> CognitoStreams -> ShowS
[CognitoStreams] -> ShowS
CognitoStreams -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CognitoStreams] -> ShowS
$cshowList :: [CognitoStreams] -> ShowS
show :: CognitoStreams -> String
$cshow :: CognitoStreams -> String
showsPrec :: Int -> CognitoStreams -> ShowS
$cshowsPrec :: Int -> CognitoStreams -> ShowS
Prelude.Show, forall x. Rep CognitoStreams x -> CognitoStreams
forall x. CognitoStreams -> Rep CognitoStreams x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CognitoStreams x -> CognitoStreams
$cfrom :: forall x. CognitoStreams -> Rep CognitoStreams x
Prelude.Generic)

-- |
-- Create a value of 'CognitoStreams' 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:
--
-- 'roleArn', 'cognitoStreams_roleArn' - The ARN of the role Amazon Cognito can assume in order to publish to the
-- stream. This role must grant access to Amazon Cognito (cognito-sync) to
-- invoke PutRecord on your Cognito stream.
--
-- 'streamName', 'cognitoStreams_streamName' - The name of the Cognito stream to receive updates. This stream must be
-- in the developers account and in the same region as the identity pool.
--
-- 'streamingStatus', 'cognitoStreams_streamingStatus' - Status of the Cognito streams. Valid values are:
--
-- ENABLED - Streaming of updates to identity pool is enabled.
--
-- DISABLED - Streaming of updates to identity pool is disabled. Bulk
-- publish will also fail if StreamingStatus is DISABLED.
newCognitoStreams ::
  CognitoStreams
newCognitoStreams :: CognitoStreams
newCognitoStreams =
  CognitoStreams'
    { $sel:roleArn:CognitoStreams' :: Maybe Text
roleArn = forall a. Maybe a
Prelude.Nothing,
      $sel:streamName:CognitoStreams' :: Maybe Text
streamName = forall a. Maybe a
Prelude.Nothing,
      $sel:streamingStatus:CognitoStreams' :: Maybe StreamingStatus
streamingStatus = forall a. Maybe a
Prelude.Nothing
    }

-- | The ARN of the role Amazon Cognito can assume in order to publish to the
-- stream. This role must grant access to Amazon Cognito (cognito-sync) to
-- invoke PutRecord on your Cognito stream.
cognitoStreams_roleArn :: Lens.Lens' CognitoStreams (Prelude.Maybe Prelude.Text)
cognitoStreams_roleArn :: Lens' CognitoStreams (Maybe Text)
cognitoStreams_roleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoStreams' {Maybe Text
roleArn :: Maybe Text
$sel:roleArn:CognitoStreams' :: CognitoStreams -> Maybe Text
roleArn} -> Maybe Text
roleArn) (\s :: CognitoStreams
s@CognitoStreams' {} Maybe Text
a -> CognitoStreams
s {$sel:roleArn:CognitoStreams' :: Maybe Text
roleArn = Maybe Text
a} :: CognitoStreams)

-- | The name of the Cognito stream to receive updates. This stream must be
-- in the developers account and in the same region as the identity pool.
cognitoStreams_streamName :: Lens.Lens' CognitoStreams (Prelude.Maybe Prelude.Text)
cognitoStreams_streamName :: Lens' CognitoStreams (Maybe Text)
cognitoStreams_streamName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoStreams' {Maybe Text
streamName :: Maybe Text
$sel:streamName:CognitoStreams' :: CognitoStreams -> Maybe Text
streamName} -> Maybe Text
streamName) (\s :: CognitoStreams
s@CognitoStreams' {} Maybe Text
a -> CognitoStreams
s {$sel:streamName:CognitoStreams' :: Maybe Text
streamName = Maybe Text
a} :: CognitoStreams)

-- | Status of the Cognito streams. Valid values are:
--
-- ENABLED - Streaming of updates to identity pool is enabled.
--
-- DISABLED - Streaming of updates to identity pool is disabled. Bulk
-- publish will also fail if StreamingStatus is DISABLED.
cognitoStreams_streamingStatus :: Lens.Lens' CognitoStreams (Prelude.Maybe StreamingStatus)
cognitoStreams_streamingStatus :: Lens' CognitoStreams (Maybe StreamingStatus)
cognitoStreams_streamingStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoStreams' {Maybe StreamingStatus
streamingStatus :: Maybe StreamingStatus
$sel:streamingStatus:CognitoStreams' :: CognitoStreams -> Maybe StreamingStatus
streamingStatus} -> Maybe StreamingStatus
streamingStatus) (\s :: CognitoStreams
s@CognitoStreams' {} Maybe StreamingStatus
a -> CognitoStreams
s {$sel:streamingStatus:CognitoStreams' :: Maybe StreamingStatus
streamingStatus = Maybe StreamingStatus
a} :: CognitoStreams)

instance Data.FromJSON CognitoStreams where
  parseJSON :: Value -> Parser CognitoStreams
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CognitoStreams"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe StreamingStatus -> CognitoStreams
CognitoStreams'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"RoleArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"StreamName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"StreamingStatus")
      )

instance Prelude.Hashable CognitoStreams where
  hashWithSalt :: Int -> CognitoStreams -> Int
hashWithSalt Int
_salt CognitoStreams' {Maybe Text
Maybe StreamingStatus
streamingStatus :: Maybe StreamingStatus
streamName :: Maybe Text
roleArn :: Maybe Text
$sel:streamingStatus:CognitoStreams' :: CognitoStreams -> Maybe StreamingStatus
$sel:streamName:CognitoStreams' :: CognitoStreams -> Maybe Text
$sel:roleArn:CognitoStreams' :: CognitoStreams -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
roleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
streamName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe StreamingStatus
streamingStatus

instance Prelude.NFData CognitoStreams where
  rnf :: CognitoStreams -> ()
rnf CognitoStreams' {Maybe Text
Maybe StreamingStatus
streamingStatus :: Maybe StreamingStatus
streamName :: Maybe Text
roleArn :: Maybe Text
$sel:streamingStatus:CognitoStreams' :: CognitoStreams -> Maybe StreamingStatus
$sel:streamName:CognitoStreams' :: CognitoStreams -> Maybe Text
$sel:roleArn:CognitoStreams' :: CognitoStreams -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
roleArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
streamName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe StreamingStatus
streamingStatus

instance Data.ToJSON CognitoStreams where
  toJSON :: CognitoStreams -> Value
toJSON CognitoStreams' {Maybe Text
Maybe StreamingStatus
streamingStatus :: Maybe StreamingStatus
streamName :: Maybe Text
roleArn :: Maybe Text
$sel:streamingStatus:CognitoStreams' :: CognitoStreams -> Maybe StreamingStatus
$sel:streamName:CognitoStreams' :: CognitoStreams -> Maybe Text
$sel:roleArn:CognitoStreams' :: CognitoStreams -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"RoleArn" 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 Text
roleArn,
            (Key
"StreamName" 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 Text
streamName,
            (Key
"StreamingStatus" 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 StreamingStatus
streamingStatus
          ]
      )