{-# 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.AppStream.CreateUsageReportSubscription
-- 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)
--
-- Creates a usage report subscription. Usage reports are generated daily.
module Amazonka.AppStream.CreateUsageReportSubscription
  ( -- * Creating a Request
    CreateUsageReportSubscription (..),
    newCreateUsageReportSubscription,

    -- * Destructuring the Response
    CreateUsageReportSubscriptionResponse (..),
    newCreateUsageReportSubscriptionResponse,

    -- * Response Lenses
    createUsageReportSubscriptionResponse_schedule,
    createUsageReportSubscriptionResponse_s3BucketName,
    createUsageReportSubscriptionResponse_httpStatus,
  )
where

import Amazonka.AppStream.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateUsageReportSubscription' smart constructor.
data CreateUsageReportSubscription = CreateUsageReportSubscription'
  {
  }
  deriving (CreateUsageReportSubscription
-> CreateUsageReportSubscription -> Bool
(CreateUsageReportSubscription
 -> CreateUsageReportSubscription -> Bool)
-> (CreateUsageReportSubscription
    -> CreateUsageReportSubscription -> Bool)
-> Eq CreateUsageReportSubscription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateUsageReportSubscription
-> CreateUsageReportSubscription -> Bool
$c/= :: CreateUsageReportSubscription
-> CreateUsageReportSubscription -> Bool
== :: CreateUsageReportSubscription
-> CreateUsageReportSubscription -> Bool
$c== :: CreateUsageReportSubscription
-> CreateUsageReportSubscription -> Bool
Prelude.Eq, ReadPrec [CreateUsageReportSubscription]
ReadPrec CreateUsageReportSubscription
Int -> ReadS CreateUsageReportSubscription
ReadS [CreateUsageReportSubscription]
(Int -> ReadS CreateUsageReportSubscription)
-> ReadS [CreateUsageReportSubscription]
-> ReadPrec CreateUsageReportSubscription
-> ReadPrec [CreateUsageReportSubscription]
-> Read CreateUsageReportSubscription
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateUsageReportSubscription]
$creadListPrec :: ReadPrec [CreateUsageReportSubscription]
readPrec :: ReadPrec CreateUsageReportSubscription
$creadPrec :: ReadPrec CreateUsageReportSubscription
readList :: ReadS [CreateUsageReportSubscription]
$creadList :: ReadS [CreateUsageReportSubscription]
readsPrec :: Int -> ReadS CreateUsageReportSubscription
$creadsPrec :: Int -> ReadS CreateUsageReportSubscription
Prelude.Read, Int -> CreateUsageReportSubscription -> ShowS
[CreateUsageReportSubscription] -> ShowS
CreateUsageReportSubscription -> String
(Int -> CreateUsageReportSubscription -> ShowS)
-> (CreateUsageReportSubscription -> String)
-> ([CreateUsageReportSubscription] -> ShowS)
-> Show CreateUsageReportSubscription
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateUsageReportSubscription] -> ShowS
$cshowList :: [CreateUsageReportSubscription] -> ShowS
show :: CreateUsageReportSubscription -> String
$cshow :: CreateUsageReportSubscription -> String
showsPrec :: Int -> CreateUsageReportSubscription -> ShowS
$cshowsPrec :: Int -> CreateUsageReportSubscription -> ShowS
Prelude.Show, (forall x.
 CreateUsageReportSubscription
 -> Rep CreateUsageReportSubscription x)
-> (forall x.
    Rep CreateUsageReportSubscription x
    -> CreateUsageReportSubscription)
-> Generic CreateUsageReportSubscription
forall x.
Rep CreateUsageReportSubscription x
-> CreateUsageReportSubscription
forall x.
CreateUsageReportSubscription
-> Rep CreateUsageReportSubscription x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateUsageReportSubscription x
-> CreateUsageReportSubscription
$cfrom :: forall x.
CreateUsageReportSubscription
-> Rep CreateUsageReportSubscription x
Prelude.Generic)

-- |
-- Create a value of 'CreateUsageReportSubscription' 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.
newCreateUsageReportSubscription ::
  CreateUsageReportSubscription
newCreateUsageReportSubscription :: CreateUsageReportSubscription
newCreateUsageReportSubscription =
  CreateUsageReportSubscription
CreateUsageReportSubscription'

instance
  Core.AWSRequest
    CreateUsageReportSubscription
  where
  type
    AWSResponse CreateUsageReportSubscription =
      CreateUsageReportSubscriptionResponse
  request :: CreateUsageReportSubscription
-> Request CreateUsageReportSubscription
request = Service
-> CreateUsageReportSubscription
-> Request CreateUsageReportSubscription
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateUsageReportSubscription
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateUsageReportSubscription)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateUsageReportSubscription))
-> Logger
-> Service
-> Proxy CreateUsageReportSubscription
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateUsageReportSubscription)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe UsageReportSchedule
-> Maybe Text -> Int -> CreateUsageReportSubscriptionResponse
CreateUsageReportSubscriptionResponse'
            (Maybe UsageReportSchedule
 -> Maybe Text -> Int -> CreateUsageReportSubscriptionResponse)
-> Either String (Maybe UsageReportSchedule)
-> Either
     String (Maybe Text -> Int -> CreateUsageReportSubscriptionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe UsageReportSchedule)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Schedule")
            Either
  String (Maybe Text -> Int -> CreateUsageReportSubscriptionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CreateUsageReportSubscriptionResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"S3BucketName")
            Either String (Int -> CreateUsageReportSubscriptionResponse)
-> Either String Int
-> Either String CreateUsageReportSubscriptionResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance
  Prelude.Hashable
    CreateUsageReportSubscription

instance Prelude.NFData CreateUsageReportSubscription

instance Core.ToHeaders CreateUsageReportSubscription where
  toHeaders :: CreateUsageReportSubscription -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateUsageReportSubscription -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"PhotonAdminProxyService.CreateUsageReportSubscription" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateUsageReportSubscription where
  toJSON :: CreateUsageReportSubscription -> Value
toJSON = Value -> CreateUsageReportSubscription -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath CreateUsageReportSubscription where
  toPath :: CreateUsageReportSubscription -> ByteString
toPath = ByteString -> CreateUsageReportSubscription -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery CreateUsageReportSubscription where
  toQuery :: CreateUsageReportSubscription -> QueryString
toQuery = QueryString -> CreateUsageReportSubscription -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateUsageReportSubscriptionResponse' smart constructor.
data CreateUsageReportSubscriptionResponse = CreateUsageReportSubscriptionResponse'
  { -- | The schedule for generating usage reports.
    CreateUsageReportSubscriptionResponse -> Maybe UsageReportSchedule
schedule :: Prelude.Maybe UsageReportSchedule,
    -- | 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.
    CreateUsageReportSubscriptionResponse -> Maybe Text
s3BucketName :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CreateUsageReportSubscriptionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateUsageReportSubscriptionResponse
-> CreateUsageReportSubscriptionResponse -> Bool
(CreateUsageReportSubscriptionResponse
 -> CreateUsageReportSubscriptionResponse -> Bool)
-> (CreateUsageReportSubscriptionResponse
    -> CreateUsageReportSubscriptionResponse -> Bool)
-> Eq CreateUsageReportSubscriptionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateUsageReportSubscriptionResponse
-> CreateUsageReportSubscriptionResponse -> Bool
$c/= :: CreateUsageReportSubscriptionResponse
-> CreateUsageReportSubscriptionResponse -> Bool
== :: CreateUsageReportSubscriptionResponse
-> CreateUsageReportSubscriptionResponse -> Bool
$c== :: CreateUsageReportSubscriptionResponse
-> CreateUsageReportSubscriptionResponse -> Bool
Prelude.Eq, ReadPrec [CreateUsageReportSubscriptionResponse]
ReadPrec CreateUsageReportSubscriptionResponse
Int -> ReadS CreateUsageReportSubscriptionResponse
ReadS [CreateUsageReportSubscriptionResponse]
(Int -> ReadS CreateUsageReportSubscriptionResponse)
-> ReadS [CreateUsageReportSubscriptionResponse]
-> ReadPrec CreateUsageReportSubscriptionResponse
-> ReadPrec [CreateUsageReportSubscriptionResponse]
-> Read CreateUsageReportSubscriptionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateUsageReportSubscriptionResponse]
$creadListPrec :: ReadPrec [CreateUsageReportSubscriptionResponse]
readPrec :: ReadPrec CreateUsageReportSubscriptionResponse
$creadPrec :: ReadPrec CreateUsageReportSubscriptionResponse
readList :: ReadS [CreateUsageReportSubscriptionResponse]
$creadList :: ReadS [CreateUsageReportSubscriptionResponse]
readsPrec :: Int -> ReadS CreateUsageReportSubscriptionResponse
$creadsPrec :: Int -> ReadS CreateUsageReportSubscriptionResponse
Prelude.Read, Int -> CreateUsageReportSubscriptionResponse -> ShowS
[CreateUsageReportSubscriptionResponse] -> ShowS
CreateUsageReportSubscriptionResponse -> String
(Int -> CreateUsageReportSubscriptionResponse -> ShowS)
-> (CreateUsageReportSubscriptionResponse -> String)
-> ([CreateUsageReportSubscriptionResponse] -> ShowS)
-> Show CreateUsageReportSubscriptionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateUsageReportSubscriptionResponse] -> ShowS
$cshowList :: [CreateUsageReportSubscriptionResponse] -> ShowS
show :: CreateUsageReportSubscriptionResponse -> String
$cshow :: CreateUsageReportSubscriptionResponse -> String
showsPrec :: Int -> CreateUsageReportSubscriptionResponse -> ShowS
$cshowsPrec :: Int -> CreateUsageReportSubscriptionResponse -> ShowS
Prelude.Show, (forall x.
 CreateUsageReportSubscriptionResponse
 -> Rep CreateUsageReportSubscriptionResponse x)
-> (forall x.
    Rep CreateUsageReportSubscriptionResponse x
    -> CreateUsageReportSubscriptionResponse)
-> Generic CreateUsageReportSubscriptionResponse
forall x.
Rep CreateUsageReportSubscriptionResponse x
-> CreateUsageReportSubscriptionResponse
forall x.
CreateUsageReportSubscriptionResponse
-> Rep CreateUsageReportSubscriptionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateUsageReportSubscriptionResponse x
-> CreateUsageReportSubscriptionResponse
$cfrom :: forall x.
CreateUsageReportSubscriptionResponse
-> Rep CreateUsageReportSubscriptionResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateUsageReportSubscriptionResponse' 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:
--
-- 'schedule', 'createUsageReportSubscriptionResponse_schedule' - The schedule for generating usage reports.
--
-- 's3BucketName', 'createUsageReportSubscriptionResponse_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.
--
-- 'httpStatus', 'createUsageReportSubscriptionResponse_httpStatus' - The response's http status code.
newCreateUsageReportSubscriptionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateUsageReportSubscriptionResponse
newCreateUsageReportSubscriptionResponse :: Int -> CreateUsageReportSubscriptionResponse
newCreateUsageReportSubscriptionResponse Int
pHttpStatus_ =
  CreateUsageReportSubscriptionResponse' :: Maybe UsageReportSchedule
-> Maybe Text -> Int -> CreateUsageReportSubscriptionResponse
CreateUsageReportSubscriptionResponse'
    { $sel:schedule:CreateUsageReportSubscriptionResponse' :: Maybe UsageReportSchedule
schedule =
        Maybe UsageReportSchedule
forall a. Maybe a
Prelude.Nothing,
      $sel:s3BucketName:CreateUsageReportSubscriptionResponse' :: Maybe Text
s3BucketName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateUsageReportSubscriptionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The schedule for generating usage reports.
createUsageReportSubscriptionResponse_schedule :: Lens.Lens' CreateUsageReportSubscriptionResponse (Prelude.Maybe UsageReportSchedule)
createUsageReportSubscriptionResponse_schedule :: (Maybe UsageReportSchedule -> f (Maybe UsageReportSchedule))
-> CreateUsageReportSubscriptionResponse
-> f CreateUsageReportSubscriptionResponse
createUsageReportSubscriptionResponse_schedule = (CreateUsageReportSubscriptionResponse
 -> Maybe UsageReportSchedule)
-> (CreateUsageReportSubscriptionResponse
    -> Maybe UsageReportSchedule
    -> CreateUsageReportSubscriptionResponse)
-> Lens
     CreateUsageReportSubscriptionResponse
     CreateUsageReportSubscriptionResponse
     (Maybe UsageReportSchedule)
     (Maybe UsageReportSchedule)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUsageReportSubscriptionResponse' {Maybe UsageReportSchedule
schedule :: Maybe UsageReportSchedule
$sel:schedule:CreateUsageReportSubscriptionResponse' :: CreateUsageReportSubscriptionResponse -> Maybe UsageReportSchedule
schedule} -> Maybe UsageReportSchedule
schedule) (\s :: CreateUsageReportSubscriptionResponse
s@CreateUsageReportSubscriptionResponse' {} Maybe UsageReportSchedule
a -> CreateUsageReportSubscriptionResponse
s {$sel:schedule:CreateUsageReportSubscriptionResponse' :: Maybe UsageReportSchedule
schedule = Maybe UsageReportSchedule
a} :: CreateUsageReportSubscriptionResponse)

-- | 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.
createUsageReportSubscriptionResponse_s3BucketName :: Lens.Lens' CreateUsageReportSubscriptionResponse (Prelude.Maybe Prelude.Text)
createUsageReportSubscriptionResponse_s3BucketName :: (Maybe Text -> f (Maybe Text))
-> CreateUsageReportSubscriptionResponse
-> f CreateUsageReportSubscriptionResponse
createUsageReportSubscriptionResponse_s3BucketName = (CreateUsageReportSubscriptionResponse -> Maybe Text)
-> (CreateUsageReportSubscriptionResponse
    -> Maybe Text -> CreateUsageReportSubscriptionResponse)
-> Lens
     CreateUsageReportSubscriptionResponse
     CreateUsageReportSubscriptionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUsageReportSubscriptionResponse' {Maybe Text
s3BucketName :: Maybe Text
$sel:s3BucketName:CreateUsageReportSubscriptionResponse' :: CreateUsageReportSubscriptionResponse -> Maybe Text
s3BucketName} -> Maybe Text
s3BucketName) (\s :: CreateUsageReportSubscriptionResponse
s@CreateUsageReportSubscriptionResponse' {} Maybe Text
a -> CreateUsageReportSubscriptionResponse
s {$sel:s3BucketName:CreateUsageReportSubscriptionResponse' :: Maybe Text
s3BucketName = Maybe Text
a} :: CreateUsageReportSubscriptionResponse)

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

instance
  Prelude.NFData
    CreateUsageReportSubscriptionResponse