{-# 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.S3.Types.AnalyticsS3BucketDestination
-- 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.S3.Types.AnalyticsS3BucketDestination where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.S3.Internal
import Amazonka.S3.Types.AnalyticsS3ExportFileFormat

-- | Contains information about where to publish the analytics results.
--
-- /See:/ 'newAnalyticsS3BucketDestination' smart constructor.
data AnalyticsS3BucketDestination = AnalyticsS3BucketDestination'
  { -- | The account ID that owns the destination S3 bucket. If no account ID is
    -- provided, the owner is not validated before exporting data.
    --
    -- Although this value is optional, we strongly recommend that you set it
    -- to help prevent problems if the destination bucket ownership changes.
    AnalyticsS3BucketDestination -> Maybe Text
bucketAccountId :: Prelude.Maybe Prelude.Text,
    -- | The prefix to use when exporting data. The prefix is prepended to all
    -- results.
    AnalyticsS3BucketDestination -> Maybe Text
prefix :: Prelude.Maybe Prelude.Text,
    -- | Specifies the file format used when exporting data to Amazon S3.
    AnalyticsS3BucketDestination -> AnalyticsS3ExportFileFormat
format :: AnalyticsS3ExportFileFormat,
    -- | The Amazon Resource Name (ARN) of the bucket to which data is exported.
    AnalyticsS3BucketDestination -> BucketName
bucket :: BucketName
  }
  deriving (AnalyticsS3BucketDestination
-> AnalyticsS3BucketDestination -> Bool
(AnalyticsS3BucketDestination
 -> AnalyticsS3BucketDestination -> Bool)
-> (AnalyticsS3BucketDestination
    -> AnalyticsS3BucketDestination -> Bool)
-> Eq AnalyticsS3BucketDestination
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AnalyticsS3BucketDestination
-> AnalyticsS3BucketDestination -> Bool
$c/= :: AnalyticsS3BucketDestination
-> AnalyticsS3BucketDestination -> Bool
== :: AnalyticsS3BucketDestination
-> AnalyticsS3BucketDestination -> Bool
$c== :: AnalyticsS3BucketDestination
-> AnalyticsS3BucketDestination -> Bool
Prelude.Eq, ReadPrec [AnalyticsS3BucketDestination]
ReadPrec AnalyticsS3BucketDestination
Int -> ReadS AnalyticsS3BucketDestination
ReadS [AnalyticsS3BucketDestination]
(Int -> ReadS AnalyticsS3BucketDestination)
-> ReadS [AnalyticsS3BucketDestination]
-> ReadPrec AnalyticsS3BucketDestination
-> ReadPrec [AnalyticsS3BucketDestination]
-> Read AnalyticsS3BucketDestination
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AnalyticsS3BucketDestination]
$creadListPrec :: ReadPrec [AnalyticsS3BucketDestination]
readPrec :: ReadPrec AnalyticsS3BucketDestination
$creadPrec :: ReadPrec AnalyticsS3BucketDestination
readList :: ReadS [AnalyticsS3BucketDestination]
$creadList :: ReadS [AnalyticsS3BucketDestination]
readsPrec :: Int -> ReadS AnalyticsS3BucketDestination
$creadsPrec :: Int -> ReadS AnalyticsS3BucketDestination
Prelude.Read, Int -> AnalyticsS3BucketDestination -> ShowS
[AnalyticsS3BucketDestination] -> ShowS
AnalyticsS3BucketDestination -> String
(Int -> AnalyticsS3BucketDestination -> ShowS)
-> (AnalyticsS3BucketDestination -> String)
-> ([AnalyticsS3BucketDestination] -> ShowS)
-> Show AnalyticsS3BucketDestination
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AnalyticsS3BucketDestination] -> ShowS
$cshowList :: [AnalyticsS3BucketDestination] -> ShowS
show :: AnalyticsS3BucketDestination -> String
$cshow :: AnalyticsS3BucketDestination -> String
showsPrec :: Int -> AnalyticsS3BucketDestination -> ShowS
$cshowsPrec :: Int -> AnalyticsS3BucketDestination -> ShowS
Prelude.Show, (forall x.
 AnalyticsS3BucketDestination -> Rep AnalyticsS3BucketDestination x)
-> (forall x.
    Rep AnalyticsS3BucketDestination x -> AnalyticsS3BucketDestination)
-> Generic AnalyticsS3BucketDestination
forall x.
Rep AnalyticsS3BucketDestination x -> AnalyticsS3BucketDestination
forall x.
AnalyticsS3BucketDestination -> Rep AnalyticsS3BucketDestination x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AnalyticsS3BucketDestination x -> AnalyticsS3BucketDestination
$cfrom :: forall x.
AnalyticsS3BucketDestination -> Rep AnalyticsS3BucketDestination x
Prelude.Generic)

-- |
-- Create a value of 'AnalyticsS3BucketDestination' 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:
--
-- 'bucketAccountId', 'analyticsS3BucketDestination_bucketAccountId' - The account ID that owns the destination S3 bucket. If no account ID is
-- provided, the owner is not validated before exporting data.
--
-- Although this value is optional, we strongly recommend that you set it
-- to help prevent problems if the destination bucket ownership changes.
--
-- 'prefix', 'analyticsS3BucketDestination_prefix' - The prefix to use when exporting data. The prefix is prepended to all
-- results.
--
-- 'format', 'analyticsS3BucketDestination_format' - Specifies the file format used when exporting data to Amazon S3.
--
-- 'bucket', 'analyticsS3BucketDestination_bucket' - The Amazon Resource Name (ARN) of the bucket to which data is exported.
newAnalyticsS3BucketDestination ::
  -- | 'format'
  AnalyticsS3ExportFileFormat ->
  -- | 'bucket'
  BucketName ->
  AnalyticsS3BucketDestination
newAnalyticsS3BucketDestination :: AnalyticsS3ExportFileFormat
-> BucketName -> AnalyticsS3BucketDestination
newAnalyticsS3BucketDestination AnalyticsS3ExportFileFormat
pFormat_ BucketName
pBucket_ =
  AnalyticsS3BucketDestination' :: Maybe Text
-> Maybe Text
-> AnalyticsS3ExportFileFormat
-> BucketName
-> AnalyticsS3BucketDestination
AnalyticsS3BucketDestination'
    { $sel:bucketAccountId:AnalyticsS3BucketDestination' :: Maybe Text
bucketAccountId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:prefix:AnalyticsS3BucketDestination' :: Maybe Text
prefix = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:format:AnalyticsS3BucketDestination' :: AnalyticsS3ExportFileFormat
format = AnalyticsS3ExportFileFormat
pFormat_,
      $sel:bucket:AnalyticsS3BucketDestination' :: BucketName
bucket = BucketName
pBucket_
    }

-- | The account ID that owns the destination S3 bucket. If no account ID is
-- provided, the owner is not validated before exporting data.
--
-- Although this value is optional, we strongly recommend that you set it
-- to help prevent problems if the destination bucket ownership changes.
analyticsS3BucketDestination_bucketAccountId :: Lens.Lens' AnalyticsS3BucketDestination (Prelude.Maybe Prelude.Text)
analyticsS3BucketDestination_bucketAccountId :: (Maybe Text -> f (Maybe Text))
-> AnalyticsS3BucketDestination -> f AnalyticsS3BucketDestination
analyticsS3BucketDestination_bucketAccountId = (AnalyticsS3BucketDestination -> Maybe Text)
-> (AnalyticsS3BucketDestination
    -> Maybe Text -> AnalyticsS3BucketDestination)
-> Lens
     AnalyticsS3BucketDestination
     AnalyticsS3BucketDestination
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnalyticsS3BucketDestination' {Maybe Text
bucketAccountId :: Maybe Text
$sel:bucketAccountId:AnalyticsS3BucketDestination' :: AnalyticsS3BucketDestination -> Maybe Text
bucketAccountId} -> Maybe Text
bucketAccountId) (\s :: AnalyticsS3BucketDestination
s@AnalyticsS3BucketDestination' {} Maybe Text
a -> AnalyticsS3BucketDestination
s {$sel:bucketAccountId:AnalyticsS3BucketDestination' :: Maybe Text
bucketAccountId = Maybe Text
a} :: AnalyticsS3BucketDestination)

-- | The prefix to use when exporting data. The prefix is prepended to all
-- results.
analyticsS3BucketDestination_prefix :: Lens.Lens' AnalyticsS3BucketDestination (Prelude.Maybe Prelude.Text)
analyticsS3BucketDestination_prefix :: (Maybe Text -> f (Maybe Text))
-> AnalyticsS3BucketDestination -> f AnalyticsS3BucketDestination
analyticsS3BucketDestination_prefix = (AnalyticsS3BucketDestination -> Maybe Text)
-> (AnalyticsS3BucketDestination
    -> Maybe Text -> AnalyticsS3BucketDestination)
-> Lens
     AnalyticsS3BucketDestination
     AnalyticsS3BucketDestination
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnalyticsS3BucketDestination' {Maybe Text
prefix :: Maybe Text
$sel:prefix:AnalyticsS3BucketDestination' :: AnalyticsS3BucketDestination -> Maybe Text
prefix} -> Maybe Text
prefix) (\s :: AnalyticsS3BucketDestination
s@AnalyticsS3BucketDestination' {} Maybe Text
a -> AnalyticsS3BucketDestination
s {$sel:prefix:AnalyticsS3BucketDestination' :: Maybe Text
prefix = Maybe Text
a} :: AnalyticsS3BucketDestination)

-- | Specifies the file format used when exporting data to Amazon S3.
analyticsS3BucketDestination_format :: Lens.Lens' AnalyticsS3BucketDestination AnalyticsS3ExportFileFormat
analyticsS3BucketDestination_format :: (AnalyticsS3ExportFileFormat -> f AnalyticsS3ExportFileFormat)
-> AnalyticsS3BucketDestination -> f AnalyticsS3BucketDestination
analyticsS3BucketDestination_format = (AnalyticsS3BucketDestination -> AnalyticsS3ExportFileFormat)
-> (AnalyticsS3BucketDestination
    -> AnalyticsS3ExportFileFormat -> AnalyticsS3BucketDestination)
-> Lens
     AnalyticsS3BucketDestination
     AnalyticsS3BucketDestination
     AnalyticsS3ExportFileFormat
     AnalyticsS3ExportFileFormat
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnalyticsS3BucketDestination' {AnalyticsS3ExportFileFormat
format :: AnalyticsS3ExportFileFormat
$sel:format:AnalyticsS3BucketDestination' :: AnalyticsS3BucketDestination -> AnalyticsS3ExportFileFormat
format} -> AnalyticsS3ExportFileFormat
format) (\s :: AnalyticsS3BucketDestination
s@AnalyticsS3BucketDestination' {} AnalyticsS3ExportFileFormat
a -> AnalyticsS3BucketDestination
s {$sel:format:AnalyticsS3BucketDestination' :: AnalyticsS3ExportFileFormat
format = AnalyticsS3ExportFileFormat
a} :: AnalyticsS3BucketDestination)

-- | The Amazon Resource Name (ARN) of the bucket to which data is exported.
analyticsS3BucketDestination_bucket :: Lens.Lens' AnalyticsS3BucketDestination BucketName
analyticsS3BucketDestination_bucket :: (BucketName -> f BucketName)
-> AnalyticsS3BucketDestination -> f AnalyticsS3BucketDestination
analyticsS3BucketDestination_bucket = (AnalyticsS3BucketDestination -> BucketName)
-> (AnalyticsS3BucketDestination
    -> BucketName -> AnalyticsS3BucketDestination)
-> Lens
     AnalyticsS3BucketDestination
     AnalyticsS3BucketDestination
     BucketName
     BucketName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnalyticsS3BucketDestination' {BucketName
bucket :: BucketName
$sel:bucket:AnalyticsS3BucketDestination' :: AnalyticsS3BucketDestination -> BucketName
bucket} -> BucketName
bucket) (\s :: AnalyticsS3BucketDestination
s@AnalyticsS3BucketDestination' {} BucketName
a -> AnalyticsS3BucketDestination
s {$sel:bucket:AnalyticsS3BucketDestination' :: BucketName
bucket = BucketName
a} :: AnalyticsS3BucketDestination)

instance Core.FromXML AnalyticsS3BucketDestination where
  parseXML :: [Node] -> Either String AnalyticsS3BucketDestination
parseXML [Node]
x =
    Maybe Text
-> Maybe Text
-> AnalyticsS3ExportFileFormat
-> BucketName
-> AnalyticsS3BucketDestination
AnalyticsS3BucketDestination'
      (Maybe Text
 -> Maybe Text
 -> AnalyticsS3ExportFileFormat
 -> BucketName
 -> AnalyticsS3BucketDestination)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> AnalyticsS3ExportFileFormat
      -> BucketName
      -> AnalyticsS3BucketDestination)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"BucketAccountId")
      Either
  String
  (Maybe Text
   -> AnalyticsS3ExportFileFormat
   -> BucketName
   -> AnalyticsS3BucketDestination)
-> Either String (Maybe Text)
-> Either
     String
     (AnalyticsS3ExportFileFormat
      -> BucketName -> AnalyticsS3BucketDestination)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Prefix")
      Either
  String
  (AnalyticsS3ExportFileFormat
   -> BucketName -> AnalyticsS3BucketDestination)
-> Either String AnalyticsS3ExportFileFormat
-> Either String (BucketName -> AnalyticsS3BucketDestination)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String AnalyticsS3ExportFileFormat
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Format")
      Either String (BucketName -> AnalyticsS3BucketDestination)
-> Either String BucketName
-> Either String AnalyticsS3BucketDestination
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String BucketName
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Bucket")

instance
  Prelude.Hashable
    AnalyticsS3BucketDestination

instance Prelude.NFData AnalyticsS3BucketDestination

instance Core.ToXML AnalyticsS3BucketDestination where
  toXML :: AnalyticsS3BucketDestination -> XML
toXML AnalyticsS3BucketDestination' {Maybe Text
BucketName
AnalyticsS3ExportFileFormat
bucket :: BucketName
format :: AnalyticsS3ExportFileFormat
prefix :: Maybe Text
bucketAccountId :: Maybe Text
$sel:bucket:AnalyticsS3BucketDestination' :: AnalyticsS3BucketDestination -> BucketName
$sel:format:AnalyticsS3BucketDestination' :: AnalyticsS3BucketDestination -> AnalyticsS3ExportFileFormat
$sel:prefix:AnalyticsS3BucketDestination' :: AnalyticsS3BucketDestination -> Maybe Text
$sel:bucketAccountId:AnalyticsS3BucketDestination' :: AnalyticsS3BucketDestination -> Maybe Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"BucketAccountId" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
bucketAccountId,
        Name
"Prefix" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
prefix,
        Name
"Format" Name -> AnalyticsS3ExportFileFormat -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= AnalyticsS3ExportFileFormat
format,
        Name
"Bucket" Name -> BucketName -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= BucketName
bucket
      ]