{-# 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.IoT.Types.Stream
-- 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.IoT.Types.Stream where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a group of files that can be streamed.
--
-- /See:/ 'newStream' smart constructor.
data Stream = Stream'
  { -- | The ID of a file associated with a stream.
    Stream -> Maybe Natural
fileId :: Prelude.Maybe Prelude.Natural,
    -- | The stream ID.
    Stream -> Maybe Text
streamId :: Prelude.Maybe Prelude.Text
  }
  deriving (Stream -> Stream -> Bool
(Stream -> Stream -> Bool)
-> (Stream -> Stream -> Bool) -> Eq Stream
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Stream -> Stream -> Bool
$c/= :: Stream -> Stream -> Bool
== :: Stream -> Stream -> Bool
$c== :: Stream -> Stream -> Bool
Prelude.Eq, ReadPrec [Stream]
ReadPrec Stream
Int -> ReadS Stream
ReadS [Stream]
(Int -> ReadS Stream)
-> ReadS [Stream]
-> ReadPrec Stream
-> ReadPrec [Stream]
-> Read Stream
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Stream]
$creadListPrec :: ReadPrec [Stream]
readPrec :: ReadPrec Stream
$creadPrec :: ReadPrec Stream
readList :: ReadS [Stream]
$creadList :: ReadS [Stream]
readsPrec :: Int -> ReadS Stream
$creadsPrec :: Int -> ReadS Stream
Prelude.Read, Int -> Stream -> ShowS
[Stream] -> ShowS
Stream -> String
(Int -> Stream -> ShowS)
-> (Stream -> String) -> ([Stream] -> ShowS) -> Show Stream
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Stream] -> ShowS
$cshowList :: [Stream] -> ShowS
show :: Stream -> String
$cshow :: Stream -> String
showsPrec :: Int -> Stream -> ShowS
$cshowsPrec :: Int -> Stream -> ShowS
Prelude.Show, (forall x. Stream -> Rep Stream x)
-> (forall x. Rep Stream x -> Stream) -> Generic Stream
forall x. Rep Stream x -> Stream
forall x. Stream -> Rep Stream x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Stream x -> Stream
$cfrom :: forall x. Stream -> Rep Stream x
Prelude.Generic)

-- |
-- Create a value of 'Stream' 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:
--
-- 'fileId', 'stream_fileId' - The ID of a file associated with a stream.
--
-- 'streamId', 'stream_streamId' - The stream ID.
newStream ::
  Stream
newStream :: Stream
newStream =
  Stream' :: Maybe Natural -> Maybe Text -> Stream
Stream'
    { $sel:fileId:Stream' :: Maybe Natural
fileId = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:streamId:Stream' :: Maybe Text
streamId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The ID of a file associated with a stream.
stream_fileId :: Lens.Lens' Stream (Prelude.Maybe Prelude.Natural)
stream_fileId :: (Maybe Natural -> f (Maybe Natural)) -> Stream -> f Stream
stream_fileId = (Stream -> Maybe Natural)
-> (Stream -> Maybe Natural -> Stream)
-> Lens Stream Stream (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Stream' {Maybe Natural
fileId :: Maybe Natural
$sel:fileId:Stream' :: Stream -> Maybe Natural
fileId} -> Maybe Natural
fileId) (\s :: Stream
s@Stream' {} Maybe Natural
a -> Stream
s {$sel:fileId:Stream' :: Maybe Natural
fileId = Maybe Natural
a} :: Stream)

-- | The stream ID.
stream_streamId :: Lens.Lens' Stream (Prelude.Maybe Prelude.Text)
stream_streamId :: (Maybe Text -> f (Maybe Text)) -> Stream -> f Stream
stream_streamId = (Stream -> Maybe Text)
-> (Stream -> Maybe Text -> Stream)
-> Lens Stream Stream (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Stream' {Maybe Text
streamId :: Maybe Text
$sel:streamId:Stream' :: Stream -> Maybe Text
streamId} -> Maybe Text
streamId) (\s :: Stream
s@Stream' {} Maybe Text
a -> Stream
s {$sel:streamId:Stream' :: Maybe Text
streamId = Maybe Text
a} :: Stream)

instance Core.FromJSON Stream where
  parseJSON :: Value -> Parser Stream
parseJSON =
    String -> (Object -> Parser Stream) -> Value -> Parser Stream
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Stream"
      ( \Object
x ->
          Maybe Natural -> Maybe Text -> Stream
Stream'
            (Maybe Natural -> Maybe Text -> Stream)
-> Parser (Maybe Natural) -> Parser (Maybe Text -> Stream)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"fileId")
            Parser (Maybe Text -> Stream)
-> Parser (Maybe Text) -> Parser Stream
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
"streamId")
      )

instance Prelude.Hashable Stream

instance Prelude.NFData Stream

instance Core.ToJSON Stream where
  toJSON :: Stream -> Value
toJSON Stream' {Maybe Natural
Maybe Text
streamId :: Maybe Text
fileId :: Maybe Natural
$sel:streamId:Stream' :: Stream -> Maybe Text
$sel:fileId:Stream' :: Stream -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"fileId" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
fileId,
            (Text
"streamId" 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
streamId
          ]
      )