{-# 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-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)
module Amazonka.CognitoSync.Types.CognitoStreams where

import Amazonka.CognitoSync.Types.StreamingStatus
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Configuration options for configure Cognito streams.
--
-- /See:/ 'newCognitoStreams' smart constructor.
data CognitoStreams = 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 -> Maybe StreamingStatus
streamingStatus :: Prelude.Maybe StreamingStatus,
    -- | 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,
    -- | 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
  }
  deriving (CognitoStreams -> CognitoStreams -> Bool
(CognitoStreams -> CognitoStreams -> Bool)
-> (CognitoStreams -> CognitoStreams -> Bool) -> Eq CognitoStreams
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]
(Int -> ReadS CognitoStreams)
-> ReadS [CognitoStreams]
-> ReadPrec CognitoStreams
-> ReadPrec [CognitoStreams]
-> Read 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
(Int -> CognitoStreams -> ShowS)
-> (CognitoStreams -> String)
-> ([CognitoStreams] -> ShowS)
-> Show CognitoStreams
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. CognitoStreams -> Rep CognitoStreams x)
-> (forall x. Rep CognitoStreams x -> CognitoStreams)
-> Generic CognitoStreams
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:
--
-- '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.
--
-- '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.
--
-- '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.
newCognitoStreams ::
  CognitoStreams
newCognitoStreams :: CognitoStreams
newCognitoStreams =
  CognitoStreams' :: Maybe StreamingStatus -> Maybe Text -> Maybe Text -> CognitoStreams
CognitoStreams'
    { $sel:streamingStatus:CognitoStreams' :: Maybe StreamingStatus
streamingStatus = Maybe StreamingStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:streamName:CognitoStreams' :: Maybe Text
streamName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:CognitoStreams' :: Maybe Text
roleArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe StreamingStatus -> f (Maybe StreamingStatus))
-> CognitoStreams -> f CognitoStreams
cognitoStreams_streamingStatus = (CognitoStreams -> Maybe StreamingStatus)
-> (CognitoStreams -> Maybe StreamingStatus -> CognitoStreams)
-> Lens
     CognitoStreams
     CognitoStreams
     (Maybe StreamingStatus)
     (Maybe 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)

-- | 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 :: (Maybe Text -> f (Maybe Text))
-> CognitoStreams -> f CognitoStreams
cognitoStreams_streamName = (CognitoStreams -> Maybe Text)
-> (CognitoStreams -> Maybe Text -> CognitoStreams)
-> Lens CognitoStreams CognitoStreams (Maybe Text) (Maybe Text)
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)

-- | 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 :: (Maybe Text -> f (Maybe Text))
-> CognitoStreams -> f CognitoStreams
cognitoStreams_roleArn = (CognitoStreams -> Maybe Text)
-> (CognitoStreams -> Maybe Text -> CognitoStreams)
-> Lens CognitoStreams CognitoStreams (Maybe Text) (Maybe Text)
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)

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

instance Prelude.Hashable CognitoStreams

instance Prelude.NFData CognitoStreams

instance Core.ToJSON CognitoStreams where
  toJSON :: CognitoStreams -> Value
toJSON CognitoStreams' {Maybe Text
Maybe StreamingStatus
roleArn :: Maybe Text
streamName :: Maybe Text
streamingStatus :: Maybe StreamingStatus
$sel:roleArn:CognitoStreams' :: CognitoStreams -> Maybe Text
$sel:streamName:CognitoStreams' :: CognitoStreams -> Maybe Text
$sel:streamingStatus:CognitoStreams' :: CognitoStreams -> Maybe StreamingStatus
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"StreamingStatus" Text -> StreamingStatus -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (StreamingStatus -> Pair) -> Maybe StreamingStatus -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe StreamingStatus
streamingStatus,
            (Text
"StreamName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
streamName,
            (Text
"RoleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
roleArn
          ]
      )