{-# 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.IoTAnalytics.Types.Channel
-- 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.IoTAnalytics.Types.Channel where

import qualified Amazonka.Core as Core
import Amazonka.IoTAnalytics.Types.ChannelStatus
import Amazonka.IoTAnalytics.Types.ChannelStorage
import Amazonka.IoTAnalytics.Types.RetentionPeriod
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A collection of data from an MQTT topic. Channels archive the raw,
-- unprocessed messages before publishing the data to a pipeline.
--
-- /See:/ 'newChannel' smart constructor.
data Channel = Channel'
  { -- | When the channel was created.
    Channel -> Maybe POSIX
creationTime :: Prelude.Maybe Core.POSIX,
    -- | The status of the channel.
    Channel -> Maybe ChannelStatus
status :: Prelude.Maybe ChannelStatus,
    -- | The last time when a new message arrived in the channel.
    --
    -- IoT Analytics updates this value at most once per minute for one
    -- channel. Hence, the @lastMessageArrivalTime@ value is an approximation.
    --
    -- This feature only applies to messages that arrived in the data store
    -- after October 23, 2020.
    Channel -> Maybe POSIX
lastMessageArrivalTime :: Prelude.Maybe Core.POSIX,
    -- | The ARN of the channel.
    Channel -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | Where channel data is stored. You can choose one of @serviceManagedS3@
    -- or @customerManagedS3@ storage. If not specified, the default is
    -- @serviceManagedS3@. You can\'t change this storage option after the
    -- channel is created.
    Channel -> Maybe ChannelStorage
storage :: Prelude.Maybe ChannelStorage,
    -- | How long, in days, message data is kept for the channel.
    Channel -> Maybe RetentionPeriod
retentionPeriod :: Prelude.Maybe RetentionPeriod,
    -- | The name of the channel.
    Channel -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | When the channel was last updated.
    Channel -> Maybe POSIX
lastUpdateTime :: Prelude.Maybe Core.POSIX
  }
  deriving (Channel -> Channel -> Bool
(Channel -> Channel -> Bool)
-> (Channel -> Channel -> Bool) -> Eq Channel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Channel -> Channel -> Bool
$c/= :: Channel -> Channel -> Bool
== :: Channel -> Channel -> Bool
$c== :: Channel -> Channel -> Bool
Prelude.Eq, ReadPrec [Channel]
ReadPrec Channel
Int -> ReadS Channel
ReadS [Channel]
(Int -> ReadS Channel)
-> ReadS [Channel]
-> ReadPrec Channel
-> ReadPrec [Channel]
-> Read Channel
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Channel]
$creadListPrec :: ReadPrec [Channel]
readPrec :: ReadPrec Channel
$creadPrec :: ReadPrec Channel
readList :: ReadS [Channel]
$creadList :: ReadS [Channel]
readsPrec :: Int -> ReadS Channel
$creadsPrec :: Int -> ReadS Channel
Prelude.Read, Int -> Channel -> ShowS
[Channel] -> ShowS
Channel -> String
(Int -> Channel -> ShowS)
-> (Channel -> String) -> ([Channel] -> ShowS) -> Show Channel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Channel] -> ShowS
$cshowList :: [Channel] -> ShowS
show :: Channel -> String
$cshow :: Channel -> String
showsPrec :: Int -> Channel -> ShowS
$cshowsPrec :: Int -> Channel -> ShowS
Prelude.Show, (forall x. Channel -> Rep Channel x)
-> (forall x. Rep Channel x -> Channel) -> Generic Channel
forall x. Rep Channel x -> Channel
forall x. Channel -> Rep Channel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Channel x -> Channel
$cfrom :: forall x. Channel -> Rep Channel x
Prelude.Generic)

-- |
-- Create a value of 'Channel' 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:
--
-- 'creationTime', 'channel_creationTime' - When the channel was created.
--
-- 'status', 'channel_status' - The status of the channel.
--
-- 'lastMessageArrivalTime', 'channel_lastMessageArrivalTime' - The last time when a new message arrived in the channel.
--
-- IoT Analytics updates this value at most once per minute for one
-- channel. Hence, the @lastMessageArrivalTime@ value is an approximation.
--
-- This feature only applies to messages that arrived in the data store
-- after October 23, 2020.
--
-- 'arn', 'channel_arn' - The ARN of the channel.
--
-- 'storage', 'channel_storage' - Where channel data is stored. You can choose one of @serviceManagedS3@
-- or @customerManagedS3@ storage. If not specified, the default is
-- @serviceManagedS3@. You can\'t change this storage option after the
-- channel is created.
--
-- 'retentionPeriod', 'channel_retentionPeriod' - How long, in days, message data is kept for the channel.
--
-- 'name', 'channel_name' - The name of the channel.
--
-- 'lastUpdateTime', 'channel_lastUpdateTime' - When the channel was last updated.
newChannel ::
  Channel
newChannel :: Channel
newChannel =
  Channel' :: Maybe POSIX
-> Maybe ChannelStatus
-> Maybe POSIX
-> Maybe Text
-> Maybe ChannelStorage
-> Maybe RetentionPeriod
-> Maybe Text
-> Maybe POSIX
-> Channel
Channel'
    { $sel:creationTime:Channel' :: Maybe POSIX
creationTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:status:Channel' :: Maybe ChannelStatus
status = Maybe ChannelStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:lastMessageArrivalTime:Channel' :: Maybe POSIX
lastMessageArrivalTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:arn:Channel' :: Maybe Text
arn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:storage:Channel' :: Maybe ChannelStorage
storage = Maybe ChannelStorage
forall a. Maybe a
Prelude.Nothing,
      $sel:retentionPeriod:Channel' :: Maybe RetentionPeriod
retentionPeriod = Maybe RetentionPeriod
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Channel' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:lastUpdateTime:Channel' :: Maybe POSIX
lastUpdateTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing
    }

-- | When the channel was created.
channel_creationTime :: Lens.Lens' Channel (Prelude.Maybe Prelude.UTCTime)
channel_creationTime :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Channel -> f Channel
channel_creationTime = (Channel -> Maybe POSIX)
-> (Channel -> Maybe POSIX -> Channel)
-> Lens Channel Channel (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {Maybe POSIX
creationTime :: Maybe POSIX
$sel:creationTime:Channel' :: Channel -> Maybe POSIX
creationTime} -> Maybe POSIX
creationTime) (\s :: Channel
s@Channel' {} Maybe POSIX
a -> Channel
s {$sel:creationTime:Channel' :: Maybe POSIX
creationTime = Maybe POSIX
a} :: Channel) ((Maybe POSIX -> f (Maybe POSIX)) -> Channel -> f Channel)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Channel
-> f Channel
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

-- | The status of the channel.
channel_status :: Lens.Lens' Channel (Prelude.Maybe ChannelStatus)
channel_status :: (Maybe ChannelStatus -> f (Maybe ChannelStatus))
-> Channel -> f Channel
channel_status = (Channel -> Maybe ChannelStatus)
-> (Channel -> Maybe ChannelStatus -> Channel)
-> Lens Channel Channel (Maybe ChannelStatus) (Maybe ChannelStatus)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {Maybe ChannelStatus
status :: Maybe ChannelStatus
$sel:status:Channel' :: Channel -> Maybe ChannelStatus
status} -> Maybe ChannelStatus
status) (\s :: Channel
s@Channel' {} Maybe ChannelStatus
a -> Channel
s {$sel:status:Channel' :: Maybe ChannelStatus
status = Maybe ChannelStatus
a} :: Channel)

-- | The last time when a new message arrived in the channel.
--
-- IoT Analytics updates this value at most once per minute for one
-- channel. Hence, the @lastMessageArrivalTime@ value is an approximation.
--
-- This feature only applies to messages that arrived in the data store
-- after October 23, 2020.
channel_lastMessageArrivalTime :: Lens.Lens' Channel (Prelude.Maybe Prelude.UTCTime)
channel_lastMessageArrivalTime :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Channel -> f Channel
channel_lastMessageArrivalTime = (Channel -> Maybe POSIX)
-> (Channel -> Maybe POSIX -> Channel)
-> Lens Channel Channel (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {Maybe POSIX
lastMessageArrivalTime :: Maybe POSIX
$sel:lastMessageArrivalTime:Channel' :: Channel -> Maybe POSIX
lastMessageArrivalTime} -> Maybe POSIX
lastMessageArrivalTime) (\s :: Channel
s@Channel' {} Maybe POSIX
a -> Channel
s {$sel:lastMessageArrivalTime:Channel' :: Maybe POSIX
lastMessageArrivalTime = Maybe POSIX
a} :: Channel) ((Maybe POSIX -> f (Maybe POSIX)) -> Channel -> f Channel)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Channel
-> f Channel
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

-- | The ARN of the channel.
channel_arn :: Lens.Lens' Channel (Prelude.Maybe Prelude.Text)
channel_arn :: (Maybe Text -> f (Maybe Text)) -> Channel -> f Channel
channel_arn = (Channel -> Maybe Text)
-> (Channel -> Maybe Text -> Channel)
-> Lens Channel Channel (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {Maybe Text
arn :: Maybe Text
$sel:arn:Channel' :: Channel -> Maybe Text
arn} -> Maybe Text
arn) (\s :: Channel
s@Channel' {} Maybe Text
a -> Channel
s {$sel:arn:Channel' :: Maybe Text
arn = Maybe Text
a} :: Channel)

-- | Where channel data is stored. You can choose one of @serviceManagedS3@
-- or @customerManagedS3@ storage. If not specified, the default is
-- @serviceManagedS3@. You can\'t change this storage option after the
-- channel is created.
channel_storage :: Lens.Lens' Channel (Prelude.Maybe ChannelStorage)
channel_storage :: (Maybe ChannelStorage -> f (Maybe ChannelStorage))
-> Channel -> f Channel
channel_storage = (Channel -> Maybe ChannelStorage)
-> (Channel -> Maybe ChannelStorage -> Channel)
-> Lens
     Channel Channel (Maybe ChannelStorage) (Maybe ChannelStorage)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {Maybe ChannelStorage
storage :: Maybe ChannelStorage
$sel:storage:Channel' :: Channel -> Maybe ChannelStorage
storage} -> Maybe ChannelStorage
storage) (\s :: Channel
s@Channel' {} Maybe ChannelStorage
a -> Channel
s {$sel:storage:Channel' :: Maybe ChannelStorage
storage = Maybe ChannelStorage
a} :: Channel)

-- | How long, in days, message data is kept for the channel.
channel_retentionPeriod :: Lens.Lens' Channel (Prelude.Maybe RetentionPeriod)
channel_retentionPeriod :: (Maybe RetentionPeriod -> f (Maybe RetentionPeriod))
-> Channel -> f Channel
channel_retentionPeriod = (Channel -> Maybe RetentionPeriod)
-> (Channel -> Maybe RetentionPeriod -> Channel)
-> Lens
     Channel Channel (Maybe RetentionPeriod) (Maybe RetentionPeriod)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {Maybe RetentionPeriod
retentionPeriod :: Maybe RetentionPeriod
$sel:retentionPeriod:Channel' :: Channel -> Maybe RetentionPeriod
retentionPeriod} -> Maybe RetentionPeriod
retentionPeriod) (\s :: Channel
s@Channel' {} Maybe RetentionPeriod
a -> Channel
s {$sel:retentionPeriod:Channel' :: Maybe RetentionPeriod
retentionPeriod = Maybe RetentionPeriod
a} :: Channel)

-- | The name of the channel.
channel_name :: Lens.Lens' Channel (Prelude.Maybe Prelude.Text)
channel_name :: (Maybe Text -> f (Maybe Text)) -> Channel -> f Channel
channel_name = (Channel -> Maybe Text)
-> (Channel -> Maybe Text -> Channel)
-> Lens Channel Channel (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {Maybe Text
name :: Maybe Text
$sel:name:Channel' :: Channel -> Maybe Text
name} -> Maybe Text
name) (\s :: Channel
s@Channel' {} Maybe Text
a -> Channel
s {$sel:name:Channel' :: Maybe Text
name = Maybe Text
a} :: Channel)

-- | When the channel was last updated.
channel_lastUpdateTime :: Lens.Lens' Channel (Prelude.Maybe Prelude.UTCTime)
channel_lastUpdateTime :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Channel -> f Channel
channel_lastUpdateTime = (Channel -> Maybe POSIX)
-> (Channel -> Maybe POSIX -> Channel)
-> Lens Channel Channel (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {Maybe POSIX
lastUpdateTime :: Maybe POSIX
$sel:lastUpdateTime:Channel' :: Channel -> Maybe POSIX
lastUpdateTime} -> Maybe POSIX
lastUpdateTime) (\s :: Channel
s@Channel' {} Maybe POSIX
a -> Channel
s {$sel:lastUpdateTime:Channel' :: Maybe POSIX
lastUpdateTime = Maybe POSIX
a} :: Channel) ((Maybe POSIX -> f (Maybe POSIX)) -> Channel -> f Channel)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Channel
-> f Channel
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

instance Core.FromJSON Channel where
  parseJSON :: Value -> Parser Channel
parseJSON =
    String -> (Object -> Parser Channel) -> Value -> Parser Channel
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Channel"
      ( \Object
x ->
          Maybe POSIX
-> Maybe ChannelStatus
-> Maybe POSIX
-> Maybe Text
-> Maybe ChannelStorage
-> Maybe RetentionPeriod
-> Maybe Text
-> Maybe POSIX
-> Channel
Channel'
            (Maybe POSIX
 -> Maybe ChannelStatus
 -> Maybe POSIX
 -> Maybe Text
 -> Maybe ChannelStorage
 -> Maybe RetentionPeriod
 -> Maybe Text
 -> Maybe POSIX
 -> Channel)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe ChannelStatus
      -> Maybe POSIX
      -> Maybe Text
      -> Maybe ChannelStorage
      -> Maybe RetentionPeriod
      -> Maybe Text
      -> Maybe POSIX
      -> Channel)
forall (f :: * -> *) a b. Functor 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
"creationTime")
            Parser
  (Maybe ChannelStatus
   -> Maybe POSIX
   -> Maybe Text
   -> Maybe ChannelStorage
   -> Maybe RetentionPeriod
   -> Maybe Text
   -> Maybe POSIX
   -> Channel)
-> Parser (Maybe ChannelStatus)
-> Parser
     (Maybe POSIX
      -> Maybe Text
      -> Maybe ChannelStorage
      -> Maybe RetentionPeriod
      -> Maybe Text
      -> Maybe POSIX
      -> Channel)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ChannelStatus)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"status")
            Parser
  (Maybe POSIX
   -> Maybe Text
   -> Maybe ChannelStorage
   -> Maybe RetentionPeriod
   -> Maybe Text
   -> Maybe POSIX
   -> Channel)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe Text
      -> Maybe ChannelStorage
      -> Maybe RetentionPeriod
      -> Maybe Text
      -> Maybe POSIX
      -> Channel)
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
"lastMessageArrivalTime")
            Parser
  (Maybe Text
   -> Maybe ChannelStorage
   -> Maybe RetentionPeriod
   -> Maybe Text
   -> Maybe POSIX
   -> Channel)
-> Parser (Maybe Text)
-> Parser
     (Maybe ChannelStorage
      -> Maybe RetentionPeriod -> Maybe Text -> Maybe POSIX -> Channel)
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
"arn")
            Parser
  (Maybe ChannelStorage
   -> Maybe RetentionPeriod -> Maybe Text -> Maybe POSIX -> Channel)
-> Parser (Maybe ChannelStorage)
-> Parser
     (Maybe RetentionPeriod -> Maybe Text -> Maybe POSIX -> Channel)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ChannelStorage)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"storage")
            Parser
  (Maybe RetentionPeriod -> Maybe Text -> Maybe POSIX -> Channel)
-> Parser (Maybe RetentionPeriod)
-> Parser (Maybe Text -> Maybe POSIX -> Channel)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe RetentionPeriod)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"retentionPeriod")
            Parser (Maybe Text -> Maybe POSIX -> Channel)
-> Parser (Maybe Text) -> Parser (Maybe POSIX -> Channel)
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
"name")
            Parser (Maybe POSIX -> Channel)
-> Parser (Maybe POSIX) -> Parser Channel
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
"lastUpdateTime")
      )

instance Prelude.Hashable Channel

instance Prelude.NFData Channel