{-# 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.AppStream.Types.UsageReportSubscription
-- 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.AppStream.Types.UsageReportSubscription where

import Amazonka.AppStream.Types.LastReportGenerationExecutionError
import Amazonka.AppStream.Types.UsageReportSchedule
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes information about the usage report subscription.
--
-- /See:/ 'newUsageReportSubscription' smart constructor.
data UsageReportSubscription = UsageReportSubscription'
  { -- | The time when the last usage report was generated.
    UsageReportSubscription -> Maybe POSIX
lastGeneratedReportDate :: Prelude.Maybe Core.POSIX,
    -- | The schedule for generating usage reports.
    UsageReportSubscription -> Maybe UsageReportSchedule
schedule :: Prelude.Maybe UsageReportSchedule,
    -- | The errors that were returned if usage reports couldn\'t be generated.
    UsageReportSubscription
-> Maybe [LastReportGenerationExecutionError]
subscriptionErrors :: Prelude.Maybe [LastReportGenerationExecutionError],
    -- | The Amazon S3 bucket where generated reports are stored.
    --
    -- If you enabled on-instance session scripts and Amazon S3 logging for
    -- your session script configuration, AppStream 2.0 created an S3 bucket to
    -- store the script output. The bucket is unique to your account and
    -- Region. When you enable usage reporting in this case, AppStream 2.0 uses
    -- the same bucket to store your usage reports. If you haven\'t already
    -- enabled on-instance session scripts, when you enable usage reports,
    -- AppStream 2.0 creates a new S3 bucket.
    UsageReportSubscription -> Maybe Text
s3BucketName :: Prelude.Maybe Prelude.Text
  }
  deriving (UsageReportSubscription -> UsageReportSubscription -> Bool
(UsageReportSubscription -> UsageReportSubscription -> Bool)
-> (UsageReportSubscription -> UsageReportSubscription -> Bool)
-> Eq UsageReportSubscription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UsageReportSubscription -> UsageReportSubscription -> Bool
$c/= :: UsageReportSubscription -> UsageReportSubscription -> Bool
== :: UsageReportSubscription -> UsageReportSubscription -> Bool
$c== :: UsageReportSubscription -> UsageReportSubscription -> Bool
Prelude.Eq, ReadPrec [UsageReportSubscription]
ReadPrec UsageReportSubscription
Int -> ReadS UsageReportSubscription
ReadS [UsageReportSubscription]
(Int -> ReadS UsageReportSubscription)
-> ReadS [UsageReportSubscription]
-> ReadPrec UsageReportSubscription
-> ReadPrec [UsageReportSubscription]
-> Read UsageReportSubscription
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UsageReportSubscription]
$creadListPrec :: ReadPrec [UsageReportSubscription]
readPrec :: ReadPrec UsageReportSubscription
$creadPrec :: ReadPrec UsageReportSubscription
readList :: ReadS [UsageReportSubscription]
$creadList :: ReadS [UsageReportSubscription]
readsPrec :: Int -> ReadS UsageReportSubscription
$creadsPrec :: Int -> ReadS UsageReportSubscription
Prelude.Read, Int -> UsageReportSubscription -> ShowS
[UsageReportSubscription] -> ShowS
UsageReportSubscription -> String
(Int -> UsageReportSubscription -> ShowS)
-> (UsageReportSubscription -> String)
-> ([UsageReportSubscription] -> ShowS)
-> Show UsageReportSubscription
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UsageReportSubscription] -> ShowS
$cshowList :: [UsageReportSubscription] -> ShowS
show :: UsageReportSubscription -> String
$cshow :: UsageReportSubscription -> String
showsPrec :: Int -> UsageReportSubscription -> ShowS
$cshowsPrec :: Int -> UsageReportSubscription -> ShowS
Prelude.Show, (forall x.
 UsageReportSubscription -> Rep UsageReportSubscription x)
-> (forall x.
    Rep UsageReportSubscription x -> UsageReportSubscription)
-> Generic UsageReportSubscription
forall x. Rep UsageReportSubscription x -> UsageReportSubscription
forall x. UsageReportSubscription -> Rep UsageReportSubscription x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UsageReportSubscription x -> UsageReportSubscription
$cfrom :: forall x. UsageReportSubscription -> Rep UsageReportSubscription x
Prelude.Generic)

-- |
-- Create a value of 'UsageReportSubscription' 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:
--
-- 'lastGeneratedReportDate', 'usageReportSubscription_lastGeneratedReportDate' - The time when the last usage report was generated.
--
-- 'schedule', 'usageReportSubscription_schedule' - The schedule for generating usage reports.
--
-- 'subscriptionErrors', 'usageReportSubscription_subscriptionErrors' - The errors that were returned if usage reports couldn\'t be generated.
--
-- 's3BucketName', 'usageReportSubscription_s3BucketName' - The Amazon S3 bucket where generated reports are stored.
--
-- If you enabled on-instance session scripts and Amazon S3 logging for
-- your session script configuration, AppStream 2.0 created an S3 bucket to
-- store the script output. The bucket is unique to your account and
-- Region. When you enable usage reporting in this case, AppStream 2.0 uses
-- the same bucket to store your usage reports. If you haven\'t already
-- enabled on-instance session scripts, when you enable usage reports,
-- AppStream 2.0 creates a new S3 bucket.
newUsageReportSubscription ::
  UsageReportSubscription
newUsageReportSubscription :: UsageReportSubscription
newUsageReportSubscription =
  UsageReportSubscription' :: Maybe POSIX
-> Maybe UsageReportSchedule
-> Maybe [LastReportGenerationExecutionError]
-> Maybe Text
-> UsageReportSubscription
UsageReportSubscription'
    { $sel:lastGeneratedReportDate:UsageReportSubscription' :: Maybe POSIX
lastGeneratedReportDate =
        Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:schedule:UsageReportSubscription' :: Maybe UsageReportSchedule
schedule = Maybe UsageReportSchedule
forall a. Maybe a
Prelude.Nothing,
      $sel:subscriptionErrors:UsageReportSubscription' :: Maybe [LastReportGenerationExecutionError]
subscriptionErrors = Maybe [LastReportGenerationExecutionError]
forall a. Maybe a
Prelude.Nothing,
      $sel:s3BucketName:UsageReportSubscription' :: Maybe Text
s3BucketName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The time when the last usage report was generated.
usageReportSubscription_lastGeneratedReportDate :: Lens.Lens' UsageReportSubscription (Prelude.Maybe Prelude.UTCTime)
usageReportSubscription_lastGeneratedReportDate :: (Maybe UTCTime -> f (Maybe UTCTime))
-> UsageReportSubscription -> f UsageReportSubscription
usageReportSubscription_lastGeneratedReportDate = (UsageReportSubscription -> Maybe POSIX)
-> (UsageReportSubscription
    -> Maybe POSIX -> UsageReportSubscription)
-> Lens
     UsageReportSubscription
     UsageReportSubscription
     (Maybe POSIX)
     (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageReportSubscription' {Maybe POSIX
lastGeneratedReportDate :: Maybe POSIX
$sel:lastGeneratedReportDate:UsageReportSubscription' :: UsageReportSubscription -> Maybe POSIX
lastGeneratedReportDate} -> Maybe POSIX
lastGeneratedReportDate) (\s :: UsageReportSubscription
s@UsageReportSubscription' {} Maybe POSIX
a -> UsageReportSubscription
s {$sel:lastGeneratedReportDate:UsageReportSubscription' :: Maybe POSIX
lastGeneratedReportDate = Maybe POSIX
a} :: UsageReportSubscription) ((Maybe POSIX -> f (Maybe POSIX))
 -> UsageReportSubscription -> f UsageReportSubscription)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> UsageReportSubscription
-> f UsageReportSubscription
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 schedule for generating usage reports.
usageReportSubscription_schedule :: Lens.Lens' UsageReportSubscription (Prelude.Maybe UsageReportSchedule)
usageReportSubscription_schedule :: (Maybe UsageReportSchedule -> f (Maybe UsageReportSchedule))
-> UsageReportSubscription -> f UsageReportSubscription
usageReportSubscription_schedule = (UsageReportSubscription -> Maybe UsageReportSchedule)
-> (UsageReportSubscription
    -> Maybe UsageReportSchedule -> UsageReportSubscription)
-> Lens
     UsageReportSubscription
     UsageReportSubscription
     (Maybe UsageReportSchedule)
     (Maybe UsageReportSchedule)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageReportSubscription' {Maybe UsageReportSchedule
schedule :: Maybe UsageReportSchedule
$sel:schedule:UsageReportSubscription' :: UsageReportSubscription -> Maybe UsageReportSchedule
schedule} -> Maybe UsageReportSchedule
schedule) (\s :: UsageReportSubscription
s@UsageReportSubscription' {} Maybe UsageReportSchedule
a -> UsageReportSubscription
s {$sel:schedule:UsageReportSubscription' :: Maybe UsageReportSchedule
schedule = Maybe UsageReportSchedule
a} :: UsageReportSubscription)

-- | The errors that were returned if usage reports couldn\'t be generated.
usageReportSubscription_subscriptionErrors :: Lens.Lens' UsageReportSubscription (Prelude.Maybe [LastReportGenerationExecutionError])
usageReportSubscription_subscriptionErrors :: (Maybe [LastReportGenerationExecutionError]
 -> f (Maybe [LastReportGenerationExecutionError]))
-> UsageReportSubscription -> f UsageReportSubscription
usageReportSubscription_subscriptionErrors = (UsageReportSubscription
 -> Maybe [LastReportGenerationExecutionError])
-> (UsageReportSubscription
    -> Maybe [LastReportGenerationExecutionError]
    -> UsageReportSubscription)
-> Lens
     UsageReportSubscription
     UsageReportSubscription
     (Maybe [LastReportGenerationExecutionError])
     (Maybe [LastReportGenerationExecutionError])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageReportSubscription' {Maybe [LastReportGenerationExecutionError]
subscriptionErrors :: Maybe [LastReportGenerationExecutionError]
$sel:subscriptionErrors:UsageReportSubscription' :: UsageReportSubscription
-> Maybe [LastReportGenerationExecutionError]
subscriptionErrors} -> Maybe [LastReportGenerationExecutionError]
subscriptionErrors) (\s :: UsageReportSubscription
s@UsageReportSubscription' {} Maybe [LastReportGenerationExecutionError]
a -> UsageReportSubscription
s {$sel:subscriptionErrors:UsageReportSubscription' :: Maybe [LastReportGenerationExecutionError]
subscriptionErrors = Maybe [LastReportGenerationExecutionError]
a} :: UsageReportSubscription) ((Maybe [LastReportGenerationExecutionError]
  -> f (Maybe [LastReportGenerationExecutionError]))
 -> UsageReportSubscription -> f UsageReportSubscription)
-> ((Maybe [LastReportGenerationExecutionError]
     -> f (Maybe [LastReportGenerationExecutionError]))
    -> Maybe [LastReportGenerationExecutionError]
    -> f (Maybe [LastReportGenerationExecutionError]))
-> (Maybe [LastReportGenerationExecutionError]
    -> f (Maybe [LastReportGenerationExecutionError]))
-> UsageReportSubscription
-> f UsageReportSubscription
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [LastReportGenerationExecutionError]
  [LastReportGenerationExecutionError]
  [LastReportGenerationExecutionError]
  [LastReportGenerationExecutionError]
-> Iso
     (Maybe [LastReportGenerationExecutionError])
     (Maybe [LastReportGenerationExecutionError])
     (Maybe [LastReportGenerationExecutionError])
     (Maybe [LastReportGenerationExecutionError])
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
  [LastReportGenerationExecutionError]
  [LastReportGenerationExecutionError]
  [LastReportGenerationExecutionError]
  [LastReportGenerationExecutionError]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon S3 bucket where generated reports are stored.
--
-- If you enabled on-instance session scripts and Amazon S3 logging for
-- your session script configuration, AppStream 2.0 created an S3 bucket to
-- store the script output. The bucket is unique to your account and
-- Region. When you enable usage reporting in this case, AppStream 2.0 uses
-- the same bucket to store your usage reports. If you haven\'t already
-- enabled on-instance session scripts, when you enable usage reports,
-- AppStream 2.0 creates a new S3 bucket.
usageReportSubscription_s3BucketName :: Lens.Lens' UsageReportSubscription (Prelude.Maybe Prelude.Text)
usageReportSubscription_s3BucketName :: (Maybe Text -> f (Maybe Text))
-> UsageReportSubscription -> f UsageReportSubscription
usageReportSubscription_s3BucketName = (UsageReportSubscription -> Maybe Text)
-> (UsageReportSubscription
    -> Maybe Text -> UsageReportSubscription)
-> Lens
     UsageReportSubscription
     UsageReportSubscription
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageReportSubscription' {Maybe Text
s3BucketName :: Maybe Text
$sel:s3BucketName:UsageReportSubscription' :: UsageReportSubscription -> Maybe Text
s3BucketName} -> Maybe Text
s3BucketName) (\s :: UsageReportSubscription
s@UsageReportSubscription' {} Maybe Text
a -> UsageReportSubscription
s {$sel:s3BucketName:UsageReportSubscription' :: Maybe Text
s3BucketName = Maybe Text
a} :: UsageReportSubscription)

instance Core.FromJSON UsageReportSubscription where
  parseJSON :: Value -> Parser UsageReportSubscription
parseJSON =
    String
-> (Object -> Parser UsageReportSubscription)
-> Value
-> Parser UsageReportSubscription
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"UsageReportSubscription"
      ( \Object
x ->
          Maybe POSIX
-> Maybe UsageReportSchedule
-> Maybe [LastReportGenerationExecutionError]
-> Maybe Text
-> UsageReportSubscription
UsageReportSubscription'
            (Maybe POSIX
 -> Maybe UsageReportSchedule
 -> Maybe [LastReportGenerationExecutionError]
 -> Maybe Text
 -> UsageReportSubscription)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe UsageReportSchedule
      -> Maybe [LastReportGenerationExecutionError]
      -> Maybe Text
      -> UsageReportSubscription)
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
"LastGeneratedReportDate")
            Parser
  (Maybe UsageReportSchedule
   -> Maybe [LastReportGenerationExecutionError]
   -> Maybe Text
   -> UsageReportSubscription)
-> Parser (Maybe UsageReportSchedule)
-> Parser
     (Maybe [LastReportGenerationExecutionError]
      -> Maybe Text -> UsageReportSubscription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe UsageReportSchedule)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Schedule")
            Parser
  (Maybe [LastReportGenerationExecutionError]
   -> Maybe Text -> UsageReportSubscription)
-> Parser (Maybe [LastReportGenerationExecutionError])
-> Parser (Maybe Text -> UsageReportSubscription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object
-> Text
-> Parser (Maybe (Maybe [LastReportGenerationExecutionError]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SubscriptionErrors"
                            Parser (Maybe (Maybe [LastReportGenerationExecutionError]))
-> Maybe [LastReportGenerationExecutionError]
-> Parser (Maybe [LastReportGenerationExecutionError])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [LastReportGenerationExecutionError]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe Text -> UsageReportSubscription)
-> Parser (Maybe Text) -> Parser UsageReportSubscription
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
"S3BucketName")
      )

instance Prelude.Hashable UsageReportSubscription

instance Prelude.NFData UsageReportSubscription