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

import qualified Amazonka.Core as Core
import Amazonka.IVS.Types.StreamHealth
import Amazonka.IVS.Types.StreamState
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies a live video stream that has been ingested and distributed.
--
-- /See:/ 'newStream' smart constructor.
data Stream = Stream'
  { -- | URL of the master playlist, required by the video player to play the HLS
    -- stream.
    Stream -> Maybe Text
playbackUrl :: Prelude.Maybe Prelude.Text,
    -- | The stream’s state.
    Stream -> Maybe StreamState
state :: Prelude.Maybe StreamState,
    -- | Time of the stream’s start. This is an ISO 8601 timestamp returned as a
    -- string.
    Stream -> Maybe POSIX
startTime :: Prelude.Maybe Core.POSIX,
    -- | Channel ARN for the stream.
    Stream -> Maybe Text
channelArn :: Prelude.Maybe Prelude.Text,
    -- | A count of concurrent views of the stream. Typically, a new view appears
    -- in @viewerCount@ within 15 seconds of when video playback starts and a
    -- view is removed from @viewerCount@ within 1 minute of when video
    -- playback ends. A value of -1 indicates that the request timed out; in
    -- this case, retry.
    Stream -> Maybe Integer
viewerCount :: Prelude.Maybe Prelude.Integer,
    -- | The stream’s health.
    Stream -> Maybe StreamHealth
health :: Prelude.Maybe StreamHealth
  }
  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:
--
-- 'playbackUrl', 'stream_playbackUrl' - URL of the master playlist, required by the video player to play the HLS
-- stream.
--
-- 'state', 'stream_state' - The stream’s state.
--
-- 'startTime', 'stream_startTime' - Time of the stream’s start. This is an ISO 8601 timestamp returned as a
-- string.
--
-- 'channelArn', 'stream_channelArn' - Channel ARN for the stream.
--
-- 'viewerCount', 'stream_viewerCount' - A count of concurrent views of the stream. Typically, a new view appears
-- in @viewerCount@ within 15 seconds of when video playback starts and a
-- view is removed from @viewerCount@ within 1 minute of when video
-- playback ends. A value of -1 indicates that the request timed out; in
-- this case, retry.
--
-- 'health', 'stream_health' - The stream’s health.
newStream ::
  Stream
newStream :: Stream
newStream =
  Stream' :: Maybe Text
-> Maybe StreamState
-> Maybe POSIX
-> Maybe Text
-> Maybe Integer
-> Maybe StreamHealth
-> Stream
Stream'
    { $sel:playbackUrl:Stream' :: Maybe Text
playbackUrl = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:state:Stream' :: Maybe StreamState
state = Maybe StreamState
forall a. Maybe a
Prelude.Nothing,
      $sel:startTime:Stream' :: Maybe POSIX
startTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:channelArn:Stream' :: Maybe Text
channelArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:viewerCount:Stream' :: Maybe Integer
viewerCount = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:health:Stream' :: Maybe StreamHealth
health = Maybe StreamHealth
forall a. Maybe a
Prelude.Nothing
    }

-- | URL of the master playlist, required by the video player to play the HLS
-- stream.
stream_playbackUrl :: Lens.Lens' Stream (Prelude.Maybe Prelude.Text)
stream_playbackUrl :: (Maybe Text -> f (Maybe Text)) -> Stream -> f Stream
stream_playbackUrl = (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
playbackUrl :: Maybe Text
$sel:playbackUrl:Stream' :: Stream -> Maybe Text
playbackUrl} -> Maybe Text
playbackUrl) (\s :: Stream
s@Stream' {} Maybe Text
a -> Stream
s {$sel:playbackUrl:Stream' :: Maybe Text
playbackUrl = Maybe Text
a} :: Stream)

-- | The stream’s state.
stream_state :: Lens.Lens' Stream (Prelude.Maybe StreamState)
stream_state :: (Maybe StreamState -> f (Maybe StreamState)) -> Stream -> f Stream
stream_state = (Stream -> Maybe StreamState)
-> (Stream -> Maybe StreamState -> Stream)
-> Lens Stream Stream (Maybe StreamState) (Maybe StreamState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Stream' {Maybe StreamState
state :: Maybe StreamState
$sel:state:Stream' :: Stream -> Maybe StreamState
state} -> Maybe StreamState
state) (\s :: Stream
s@Stream' {} Maybe StreamState
a -> Stream
s {$sel:state:Stream' :: Maybe StreamState
state = Maybe StreamState
a} :: Stream)

-- | Time of the stream’s start. This is an ISO 8601 timestamp returned as a
-- string.
stream_startTime :: Lens.Lens' Stream (Prelude.Maybe Prelude.UTCTime)
stream_startTime :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Stream -> f Stream
stream_startTime = (Stream -> Maybe POSIX)
-> (Stream -> Maybe POSIX -> Stream)
-> Lens Stream Stream (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Stream' {Maybe POSIX
startTime :: Maybe POSIX
$sel:startTime:Stream' :: Stream -> Maybe POSIX
startTime} -> Maybe POSIX
startTime) (\s :: Stream
s@Stream' {} Maybe POSIX
a -> Stream
s {$sel:startTime:Stream' :: Maybe POSIX
startTime = Maybe POSIX
a} :: Stream) ((Maybe POSIX -> f (Maybe POSIX)) -> Stream -> f Stream)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Stream
-> f Stream
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 AnIso POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | Channel ARN for the stream.
stream_channelArn :: Lens.Lens' Stream (Prelude.Maybe Prelude.Text)
stream_channelArn :: (Maybe Text -> f (Maybe Text)) -> Stream -> f Stream
stream_channelArn = (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
channelArn :: Maybe Text
$sel:channelArn:Stream' :: Stream -> Maybe Text
channelArn} -> Maybe Text
channelArn) (\s :: Stream
s@Stream' {} Maybe Text
a -> Stream
s {$sel:channelArn:Stream' :: Maybe Text
channelArn = Maybe Text
a} :: Stream)

-- | A count of concurrent views of the stream. Typically, a new view appears
-- in @viewerCount@ within 15 seconds of when video playback starts and a
-- view is removed from @viewerCount@ within 1 minute of when video
-- playback ends. A value of -1 indicates that the request timed out; in
-- this case, retry.
stream_viewerCount :: Lens.Lens' Stream (Prelude.Maybe Prelude.Integer)
stream_viewerCount :: (Maybe Integer -> f (Maybe Integer)) -> Stream -> f Stream
stream_viewerCount = (Stream -> Maybe Integer)
-> (Stream -> Maybe Integer -> Stream)
-> Lens Stream Stream (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Stream' {Maybe Integer
viewerCount :: Maybe Integer
$sel:viewerCount:Stream' :: Stream -> Maybe Integer
viewerCount} -> Maybe Integer
viewerCount) (\s :: Stream
s@Stream' {} Maybe Integer
a -> Stream
s {$sel:viewerCount:Stream' :: Maybe Integer
viewerCount = Maybe Integer
a} :: Stream)

-- | The stream’s health.
stream_health :: Lens.Lens' Stream (Prelude.Maybe StreamHealth)
stream_health :: (Maybe StreamHealth -> f (Maybe StreamHealth))
-> Stream -> f Stream
stream_health = (Stream -> Maybe StreamHealth)
-> (Stream -> Maybe StreamHealth -> Stream)
-> Lens Stream Stream (Maybe StreamHealth) (Maybe StreamHealth)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Stream' {Maybe StreamHealth
health :: Maybe StreamHealth
$sel:health:Stream' :: Stream -> Maybe StreamHealth
health} -> Maybe StreamHealth
health) (\s :: Stream
s@Stream' {} Maybe StreamHealth
a -> Stream
s {$sel:health:Stream' :: Maybe StreamHealth
health = Maybe StreamHealth
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 Text
-> Maybe StreamState
-> Maybe POSIX
-> Maybe Text
-> Maybe Integer
-> Maybe StreamHealth
-> Stream
Stream'
            (Maybe Text
 -> Maybe StreamState
 -> Maybe POSIX
 -> Maybe Text
 -> Maybe Integer
 -> Maybe StreamHealth
 -> Stream)
-> Parser (Maybe Text)
-> Parser
     (Maybe StreamState
      -> Maybe POSIX
      -> Maybe Text
      -> Maybe Integer
      -> Maybe StreamHealth
      -> Stream)
forall (f :: * -> *) a b. Functor 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
"playbackUrl")
            Parser
  (Maybe StreamState
   -> Maybe POSIX
   -> Maybe Text
   -> Maybe Integer
   -> Maybe StreamHealth
   -> Stream)
-> Parser (Maybe StreamState)
-> Parser
     (Maybe POSIX
      -> Maybe Text -> Maybe Integer -> Maybe StreamHealth -> Stream)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe StreamState)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"state")
            Parser
  (Maybe POSIX
   -> Maybe Text -> Maybe Integer -> Maybe StreamHealth -> Stream)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe Text -> Maybe Integer -> Maybe StreamHealth -> Stream)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"startTime")
            Parser
  (Maybe Text -> Maybe Integer -> Maybe StreamHealth -> Stream)
-> Parser (Maybe Text)
-> Parser (Maybe Integer -> Maybe StreamHealth -> 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
"channelArn")
            Parser (Maybe Integer -> Maybe StreamHealth -> Stream)
-> Parser (Maybe Integer) -> Parser (Maybe StreamHealth -> Stream)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"viewerCount")
            Parser (Maybe StreamHealth -> Stream)
-> Parser (Maybe StreamHealth) -> Parser Stream
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe StreamHealth)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"health")
      )

instance Prelude.Hashable Stream

instance Prelude.NFData Stream