{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.SampleChannelData
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves a sample of messages from the specified channel ingested
-- during the specified timeframe. Up to 10 messages can be retrieved.
module Amazonka.IoTAnalytics.SampleChannelData
  ( -- * Creating a Request
    SampleChannelData (..),
    newSampleChannelData,

    -- * Request Lenses
    sampleChannelData_endTime,
    sampleChannelData_maxMessages,
    sampleChannelData_startTime,
    sampleChannelData_channelName,

    -- * Destructuring the Response
    SampleChannelDataResponse (..),
    newSampleChannelDataResponse,

    -- * Response Lenses
    sampleChannelDataResponse_payloads,
    sampleChannelDataResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTAnalytics.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newSampleChannelData' smart constructor.
data SampleChannelData = SampleChannelData'
  { -- | The end of the time window from which sample messages are retrieved.
    SampleChannelData -> Maybe POSIX
endTime :: Prelude.Maybe Data.POSIX,
    -- | The number of sample messages to be retrieved. The limit is 10. The
    -- default is also 10.
    SampleChannelData -> Maybe Natural
maxMessages :: Prelude.Maybe Prelude.Natural,
    -- | The start of the time window from which sample messages are retrieved.
    SampleChannelData -> Maybe POSIX
startTime :: Prelude.Maybe Data.POSIX,
    -- | The name of the channel whose message samples are retrieved.
    SampleChannelData -> Text
channelName :: Prelude.Text
  }
  deriving (SampleChannelData -> SampleChannelData -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SampleChannelData -> SampleChannelData -> Bool
$c/= :: SampleChannelData -> SampleChannelData -> Bool
== :: SampleChannelData -> SampleChannelData -> Bool
$c== :: SampleChannelData -> SampleChannelData -> Bool
Prelude.Eq, ReadPrec [SampleChannelData]
ReadPrec SampleChannelData
Int -> ReadS SampleChannelData
ReadS [SampleChannelData]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SampleChannelData]
$creadListPrec :: ReadPrec [SampleChannelData]
readPrec :: ReadPrec SampleChannelData
$creadPrec :: ReadPrec SampleChannelData
readList :: ReadS [SampleChannelData]
$creadList :: ReadS [SampleChannelData]
readsPrec :: Int -> ReadS SampleChannelData
$creadsPrec :: Int -> ReadS SampleChannelData
Prelude.Read, Int -> SampleChannelData -> ShowS
[SampleChannelData] -> ShowS
SampleChannelData -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SampleChannelData] -> ShowS
$cshowList :: [SampleChannelData] -> ShowS
show :: SampleChannelData -> String
$cshow :: SampleChannelData -> String
showsPrec :: Int -> SampleChannelData -> ShowS
$cshowsPrec :: Int -> SampleChannelData -> ShowS
Prelude.Show, forall x. Rep SampleChannelData x -> SampleChannelData
forall x. SampleChannelData -> Rep SampleChannelData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SampleChannelData x -> SampleChannelData
$cfrom :: forall x. SampleChannelData -> Rep SampleChannelData x
Prelude.Generic)

-- |
-- Create a value of 'SampleChannelData' 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:
--
-- 'endTime', 'sampleChannelData_endTime' - The end of the time window from which sample messages are retrieved.
--
-- 'maxMessages', 'sampleChannelData_maxMessages' - The number of sample messages to be retrieved. The limit is 10. The
-- default is also 10.
--
-- 'startTime', 'sampleChannelData_startTime' - The start of the time window from which sample messages are retrieved.
--
-- 'channelName', 'sampleChannelData_channelName' - The name of the channel whose message samples are retrieved.
newSampleChannelData ::
  -- | 'channelName'
  Prelude.Text ->
  SampleChannelData
newSampleChannelData :: Text -> SampleChannelData
newSampleChannelData Text
pChannelName_ =
  SampleChannelData'
    { $sel:endTime:SampleChannelData' :: Maybe POSIX
endTime = forall a. Maybe a
Prelude.Nothing,
      $sel:maxMessages:SampleChannelData' :: Maybe Natural
maxMessages = forall a. Maybe a
Prelude.Nothing,
      $sel:startTime:SampleChannelData' :: Maybe POSIX
startTime = forall a. Maybe a
Prelude.Nothing,
      $sel:channelName:SampleChannelData' :: Text
channelName = Text
pChannelName_
    }

-- | The end of the time window from which sample messages are retrieved.
sampleChannelData_endTime :: Lens.Lens' SampleChannelData (Prelude.Maybe Prelude.UTCTime)
sampleChannelData_endTime :: Lens' SampleChannelData (Maybe UTCTime)
sampleChannelData_endTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SampleChannelData' {Maybe POSIX
endTime :: Maybe POSIX
$sel:endTime:SampleChannelData' :: SampleChannelData -> Maybe POSIX
endTime} -> Maybe POSIX
endTime) (\s :: SampleChannelData
s@SampleChannelData' {} Maybe POSIX
a -> SampleChannelData
s {$sel:endTime:SampleChannelData' :: Maybe POSIX
endTime = Maybe POSIX
a} :: SampleChannelData) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The number of sample messages to be retrieved. The limit is 10. The
-- default is also 10.
sampleChannelData_maxMessages :: Lens.Lens' SampleChannelData (Prelude.Maybe Prelude.Natural)
sampleChannelData_maxMessages :: Lens' SampleChannelData (Maybe Natural)
sampleChannelData_maxMessages = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SampleChannelData' {Maybe Natural
maxMessages :: Maybe Natural
$sel:maxMessages:SampleChannelData' :: SampleChannelData -> Maybe Natural
maxMessages} -> Maybe Natural
maxMessages) (\s :: SampleChannelData
s@SampleChannelData' {} Maybe Natural
a -> SampleChannelData
s {$sel:maxMessages:SampleChannelData' :: Maybe Natural
maxMessages = Maybe Natural
a} :: SampleChannelData)

-- | The start of the time window from which sample messages are retrieved.
sampleChannelData_startTime :: Lens.Lens' SampleChannelData (Prelude.Maybe Prelude.UTCTime)
sampleChannelData_startTime :: Lens' SampleChannelData (Maybe UTCTime)
sampleChannelData_startTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SampleChannelData' {Maybe POSIX
startTime :: Maybe POSIX
$sel:startTime:SampleChannelData' :: SampleChannelData -> Maybe POSIX
startTime} -> Maybe POSIX
startTime) (\s :: SampleChannelData
s@SampleChannelData' {} Maybe POSIX
a -> SampleChannelData
s {$sel:startTime:SampleChannelData' :: Maybe POSIX
startTime = Maybe POSIX
a} :: SampleChannelData) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The name of the channel whose message samples are retrieved.
sampleChannelData_channelName :: Lens.Lens' SampleChannelData Prelude.Text
sampleChannelData_channelName :: Lens' SampleChannelData Text
sampleChannelData_channelName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SampleChannelData' {Text
channelName :: Text
$sel:channelName:SampleChannelData' :: SampleChannelData -> Text
channelName} -> Text
channelName) (\s :: SampleChannelData
s@SampleChannelData' {} Text
a -> SampleChannelData
s {$sel:channelName:SampleChannelData' :: Text
channelName = Text
a} :: SampleChannelData)

instance Core.AWSRequest SampleChannelData where
  type
    AWSResponse SampleChannelData =
      SampleChannelDataResponse
  request :: (Service -> Service)
-> SampleChannelData -> Request SampleChannelData
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy SampleChannelData
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SampleChannelData)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe (NonEmpty Base64) -> Int -> SampleChannelDataResponse
SampleChannelDataResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"payloads")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable SampleChannelData where
  hashWithSalt :: Int -> SampleChannelData -> Int
hashWithSalt Int
_salt SampleChannelData' {Maybe Natural
Maybe POSIX
Text
channelName :: Text
startTime :: Maybe POSIX
maxMessages :: Maybe Natural
endTime :: Maybe POSIX
$sel:channelName:SampleChannelData' :: SampleChannelData -> Text
$sel:startTime:SampleChannelData' :: SampleChannelData -> Maybe POSIX
$sel:maxMessages:SampleChannelData' :: SampleChannelData -> Maybe Natural
$sel:endTime:SampleChannelData' :: SampleChannelData -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
endTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxMessages
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
startTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
channelName

instance Prelude.NFData SampleChannelData where
  rnf :: SampleChannelData -> ()
rnf SampleChannelData' {Maybe Natural
Maybe POSIX
Text
channelName :: Text
startTime :: Maybe POSIX
maxMessages :: Maybe Natural
endTime :: Maybe POSIX
$sel:channelName:SampleChannelData' :: SampleChannelData -> Text
$sel:startTime:SampleChannelData' :: SampleChannelData -> Maybe POSIX
$sel:maxMessages:SampleChannelData' :: SampleChannelData -> Maybe Natural
$sel:endTime:SampleChannelData' :: SampleChannelData -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
endTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxMessages
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
startTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
channelName

instance Data.ToHeaders SampleChannelData where
  toHeaders :: SampleChannelData -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToPath SampleChannelData where
  toPath :: SampleChannelData -> ByteString
toPath SampleChannelData' {Maybe Natural
Maybe POSIX
Text
channelName :: Text
startTime :: Maybe POSIX
maxMessages :: Maybe Natural
endTime :: Maybe POSIX
$sel:channelName:SampleChannelData' :: SampleChannelData -> Text
$sel:startTime:SampleChannelData' :: SampleChannelData -> Maybe POSIX
$sel:maxMessages:SampleChannelData' :: SampleChannelData -> Maybe Natural
$sel:endTime:SampleChannelData' :: SampleChannelData -> Maybe POSIX
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/channels/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
channelName, ByteString
"/sample"]

instance Data.ToQuery SampleChannelData where
  toQuery :: SampleChannelData -> QueryString
toQuery SampleChannelData' {Maybe Natural
Maybe POSIX
Text
channelName :: Text
startTime :: Maybe POSIX
maxMessages :: Maybe Natural
endTime :: Maybe POSIX
$sel:channelName:SampleChannelData' :: SampleChannelData -> Text
$sel:startTime:SampleChannelData' :: SampleChannelData -> Maybe POSIX
$sel:maxMessages:SampleChannelData' :: SampleChannelData -> Maybe Natural
$sel:endTime:SampleChannelData' :: SampleChannelData -> Maybe POSIX
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"endTime" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe POSIX
endTime,
        ByteString
"maxMessages" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Natural
maxMessages,
        ByteString
"startTime" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe POSIX
startTime
      ]

-- | /See:/ 'newSampleChannelDataResponse' smart constructor.
data SampleChannelDataResponse = SampleChannelDataResponse'
  { -- | The list of message samples. Each sample message is returned as a
    -- base64-encoded string.
    SampleChannelDataResponse -> Maybe (NonEmpty Base64)
payloads :: Prelude.Maybe (Prelude.NonEmpty Data.Base64),
    -- | The response's http status code.
    SampleChannelDataResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (SampleChannelDataResponse -> SampleChannelDataResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SampleChannelDataResponse -> SampleChannelDataResponse -> Bool
$c/= :: SampleChannelDataResponse -> SampleChannelDataResponse -> Bool
== :: SampleChannelDataResponse -> SampleChannelDataResponse -> Bool
$c== :: SampleChannelDataResponse -> SampleChannelDataResponse -> Bool
Prelude.Eq, ReadPrec [SampleChannelDataResponse]
ReadPrec SampleChannelDataResponse
Int -> ReadS SampleChannelDataResponse
ReadS [SampleChannelDataResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SampleChannelDataResponse]
$creadListPrec :: ReadPrec [SampleChannelDataResponse]
readPrec :: ReadPrec SampleChannelDataResponse
$creadPrec :: ReadPrec SampleChannelDataResponse
readList :: ReadS [SampleChannelDataResponse]
$creadList :: ReadS [SampleChannelDataResponse]
readsPrec :: Int -> ReadS SampleChannelDataResponse
$creadsPrec :: Int -> ReadS SampleChannelDataResponse
Prelude.Read, Int -> SampleChannelDataResponse -> ShowS
[SampleChannelDataResponse] -> ShowS
SampleChannelDataResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SampleChannelDataResponse] -> ShowS
$cshowList :: [SampleChannelDataResponse] -> ShowS
show :: SampleChannelDataResponse -> String
$cshow :: SampleChannelDataResponse -> String
showsPrec :: Int -> SampleChannelDataResponse -> ShowS
$cshowsPrec :: Int -> SampleChannelDataResponse -> ShowS
Prelude.Show, forall x.
Rep SampleChannelDataResponse x -> SampleChannelDataResponse
forall x.
SampleChannelDataResponse -> Rep SampleChannelDataResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SampleChannelDataResponse x -> SampleChannelDataResponse
$cfrom :: forall x.
SampleChannelDataResponse -> Rep SampleChannelDataResponse x
Prelude.Generic)

-- |
-- Create a value of 'SampleChannelDataResponse' 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:
--
-- 'payloads', 'sampleChannelDataResponse_payloads' - The list of message samples. Each sample message is returned as a
-- base64-encoded string.
--
-- 'httpStatus', 'sampleChannelDataResponse_httpStatus' - The response's http status code.
newSampleChannelDataResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SampleChannelDataResponse
newSampleChannelDataResponse :: Int -> SampleChannelDataResponse
newSampleChannelDataResponse Int
pHttpStatus_ =
  SampleChannelDataResponse'
    { $sel:payloads:SampleChannelDataResponse' :: Maybe (NonEmpty Base64)
payloads =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:SampleChannelDataResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of message samples. Each sample message is returned as a
-- base64-encoded string.
sampleChannelDataResponse_payloads :: Lens.Lens' SampleChannelDataResponse (Prelude.Maybe (Prelude.NonEmpty Prelude.ByteString))
sampleChannelDataResponse_payloads :: Lens' SampleChannelDataResponse (Maybe (NonEmpty ByteString))
sampleChannelDataResponse_payloads = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SampleChannelDataResponse' {Maybe (NonEmpty Base64)
payloads :: Maybe (NonEmpty Base64)
$sel:payloads:SampleChannelDataResponse' :: SampleChannelDataResponse -> Maybe (NonEmpty Base64)
payloads} -> Maybe (NonEmpty Base64)
payloads) (\s :: SampleChannelDataResponse
s@SampleChannelDataResponse' {} Maybe (NonEmpty Base64)
a -> SampleChannelDataResponse
s {$sel:payloads:SampleChannelDataResponse' :: Maybe (NonEmpty Base64)
payloads = Maybe (NonEmpty Base64)
a} :: SampleChannelDataResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
sampleChannelDataResponse_httpStatus :: Lens.Lens' SampleChannelDataResponse Prelude.Int
sampleChannelDataResponse_httpStatus :: Lens' SampleChannelDataResponse Int
sampleChannelDataResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SampleChannelDataResponse' {Int
httpStatus :: Int
$sel:httpStatus:SampleChannelDataResponse' :: SampleChannelDataResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: SampleChannelDataResponse
s@SampleChannelDataResponse' {} Int
a -> SampleChannelDataResponse
s {$sel:httpStatus:SampleChannelDataResponse' :: Int
httpStatus = Int
a} :: SampleChannelDataResponse)

instance Prelude.NFData SampleChannelDataResponse where
  rnf :: SampleChannelDataResponse -> ()
rnf SampleChannelDataResponse' {Int
Maybe (NonEmpty Base64)
httpStatus :: Int
payloads :: Maybe (NonEmpty Base64)
$sel:httpStatus:SampleChannelDataResponse' :: SampleChannelDataResponse -> Int
$sel:payloads:SampleChannelDataResponse' :: SampleChannelDataResponse -> Maybe (NonEmpty Base64)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Base64)
payloads
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus