{-# 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.S3DestinationConfiguration
-- 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.S3DestinationConfiguration where

import qualified Amazonka.Core as Core
import Amazonka.IoTAnalytics.Types.GlueConfiguration
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Configuration information for delivery of dataset contents to Amazon
-- Simple Storage Service (Amazon S3).
--
-- /See:/ 'newS3DestinationConfiguration' smart constructor.
data S3DestinationConfiguration = S3DestinationConfiguration'
  { -- | Configuration information for coordination with Glue, a fully managed
    -- extract, transform and load (ETL) service.
    S3DestinationConfiguration -> Maybe GlueConfiguration
glueConfiguration :: Prelude.Maybe GlueConfiguration,
    -- | The name of the S3 bucket to which dataset contents are delivered.
    S3DestinationConfiguration -> Text
bucket :: Prelude.Text,
    -- | The key of the dataset contents object in an S3 bucket. Each object has
    -- a key that is a unique identifier. Each object has exactly one key.
    --
    -- You can create a unique key with the following options:
    --
    -- -   Use @!{iotanalytics:scheduleTime}@ to insert the time of a scheduled
    --     SQL query run.
    --
    -- -   Use @!{iotanalytics:versionId}@ to insert a unique hash that
    --     identifies a dataset content.
    --
    -- -   Use @!{iotanalytics:creationTime}@ to insert the creation time of a
    --     dataset content.
    --
    -- The following example creates a unique key for a CSV file:
    -- @dataset\/mydataset\/!{iotanalytics:scheduleTime}\/!{iotanalytics:versionId}.csv@
    --
    -- If you don\'t use @!{iotanalytics:versionId}@ to specify the key, you
    -- might get duplicate keys. For example, you might have two dataset
    -- contents with the same @scheduleTime@ but different @versionId@s. This
    -- means that one dataset content overwrites the other.
    S3DestinationConfiguration -> Text
key :: Prelude.Text,
    -- | The ARN of the role that grants IoT Analytics permission to interact
    -- with your Amazon S3 and Glue resources.
    S3DestinationConfiguration -> Text
roleArn :: Prelude.Text
  }
  deriving (S3DestinationConfiguration -> S3DestinationConfiguration -> Bool
(S3DestinationConfiguration -> S3DestinationConfiguration -> Bool)
-> (S3DestinationConfiguration
    -> S3DestinationConfiguration -> Bool)
-> Eq S3DestinationConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: S3DestinationConfiguration -> S3DestinationConfiguration -> Bool
$c/= :: S3DestinationConfiguration -> S3DestinationConfiguration -> Bool
== :: S3DestinationConfiguration -> S3DestinationConfiguration -> Bool
$c== :: S3DestinationConfiguration -> S3DestinationConfiguration -> Bool
Prelude.Eq, ReadPrec [S3DestinationConfiguration]
ReadPrec S3DestinationConfiguration
Int -> ReadS S3DestinationConfiguration
ReadS [S3DestinationConfiguration]
(Int -> ReadS S3DestinationConfiguration)
-> ReadS [S3DestinationConfiguration]
-> ReadPrec S3DestinationConfiguration
-> ReadPrec [S3DestinationConfiguration]
-> Read S3DestinationConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [S3DestinationConfiguration]
$creadListPrec :: ReadPrec [S3DestinationConfiguration]
readPrec :: ReadPrec S3DestinationConfiguration
$creadPrec :: ReadPrec S3DestinationConfiguration
readList :: ReadS [S3DestinationConfiguration]
$creadList :: ReadS [S3DestinationConfiguration]
readsPrec :: Int -> ReadS S3DestinationConfiguration
$creadsPrec :: Int -> ReadS S3DestinationConfiguration
Prelude.Read, Int -> S3DestinationConfiguration -> ShowS
[S3DestinationConfiguration] -> ShowS
S3DestinationConfiguration -> String
(Int -> S3DestinationConfiguration -> ShowS)
-> (S3DestinationConfiguration -> String)
-> ([S3DestinationConfiguration] -> ShowS)
-> Show S3DestinationConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [S3DestinationConfiguration] -> ShowS
$cshowList :: [S3DestinationConfiguration] -> ShowS
show :: S3DestinationConfiguration -> String
$cshow :: S3DestinationConfiguration -> String
showsPrec :: Int -> S3DestinationConfiguration -> ShowS
$cshowsPrec :: Int -> S3DestinationConfiguration -> ShowS
Prelude.Show, (forall x.
 S3DestinationConfiguration -> Rep S3DestinationConfiguration x)
-> (forall x.
    Rep S3DestinationConfiguration x -> S3DestinationConfiguration)
-> Generic S3DestinationConfiguration
forall x.
Rep S3DestinationConfiguration x -> S3DestinationConfiguration
forall x.
S3DestinationConfiguration -> Rep S3DestinationConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep S3DestinationConfiguration x -> S3DestinationConfiguration
$cfrom :: forall x.
S3DestinationConfiguration -> Rep S3DestinationConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'S3DestinationConfiguration' 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:
--
-- 'glueConfiguration', 's3DestinationConfiguration_glueConfiguration' - Configuration information for coordination with Glue, a fully managed
-- extract, transform and load (ETL) service.
--
-- 'bucket', 's3DestinationConfiguration_bucket' - The name of the S3 bucket to which dataset contents are delivered.
--
-- 'key', 's3DestinationConfiguration_key' - The key of the dataset contents object in an S3 bucket. Each object has
-- a key that is a unique identifier. Each object has exactly one key.
--
-- You can create a unique key with the following options:
--
-- -   Use @!{iotanalytics:scheduleTime}@ to insert the time of a scheduled
--     SQL query run.
--
-- -   Use @!{iotanalytics:versionId}@ to insert a unique hash that
--     identifies a dataset content.
--
-- -   Use @!{iotanalytics:creationTime}@ to insert the creation time of a
--     dataset content.
--
-- The following example creates a unique key for a CSV file:
-- @dataset\/mydataset\/!{iotanalytics:scheduleTime}\/!{iotanalytics:versionId}.csv@
--
-- If you don\'t use @!{iotanalytics:versionId}@ to specify the key, you
-- might get duplicate keys. For example, you might have two dataset
-- contents with the same @scheduleTime@ but different @versionId@s. This
-- means that one dataset content overwrites the other.
--
-- 'roleArn', 's3DestinationConfiguration_roleArn' - The ARN of the role that grants IoT Analytics permission to interact
-- with your Amazon S3 and Glue resources.
newS3DestinationConfiguration ::
  -- | 'bucket'
  Prelude.Text ->
  -- | 'key'
  Prelude.Text ->
  -- | 'roleArn'
  Prelude.Text ->
  S3DestinationConfiguration
newS3DestinationConfiguration :: Text -> Text -> Text -> S3DestinationConfiguration
newS3DestinationConfiguration
  Text
pBucket_
  Text
pKey_
  Text
pRoleArn_ =
    S3DestinationConfiguration' :: Maybe GlueConfiguration
-> Text -> Text -> Text -> S3DestinationConfiguration
S3DestinationConfiguration'
      { $sel:glueConfiguration:S3DestinationConfiguration' :: Maybe GlueConfiguration
glueConfiguration =
          Maybe GlueConfiguration
forall a. Maybe a
Prelude.Nothing,
        $sel:bucket:S3DestinationConfiguration' :: Text
bucket = Text
pBucket_,
        $sel:key:S3DestinationConfiguration' :: Text
key = Text
pKey_,
        $sel:roleArn:S3DestinationConfiguration' :: Text
roleArn = Text
pRoleArn_
      }

-- | Configuration information for coordination with Glue, a fully managed
-- extract, transform and load (ETL) service.
s3DestinationConfiguration_glueConfiguration :: Lens.Lens' S3DestinationConfiguration (Prelude.Maybe GlueConfiguration)
s3DestinationConfiguration_glueConfiguration :: (Maybe GlueConfiguration -> f (Maybe GlueConfiguration))
-> S3DestinationConfiguration -> f S3DestinationConfiguration
s3DestinationConfiguration_glueConfiguration = (S3DestinationConfiguration -> Maybe GlueConfiguration)
-> (S3DestinationConfiguration
    -> Maybe GlueConfiguration -> S3DestinationConfiguration)
-> Lens
     S3DestinationConfiguration
     S3DestinationConfiguration
     (Maybe GlueConfiguration)
     (Maybe GlueConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3DestinationConfiguration' {Maybe GlueConfiguration
glueConfiguration :: Maybe GlueConfiguration
$sel:glueConfiguration:S3DestinationConfiguration' :: S3DestinationConfiguration -> Maybe GlueConfiguration
glueConfiguration} -> Maybe GlueConfiguration
glueConfiguration) (\s :: S3DestinationConfiguration
s@S3DestinationConfiguration' {} Maybe GlueConfiguration
a -> S3DestinationConfiguration
s {$sel:glueConfiguration:S3DestinationConfiguration' :: Maybe GlueConfiguration
glueConfiguration = Maybe GlueConfiguration
a} :: S3DestinationConfiguration)

-- | The name of the S3 bucket to which dataset contents are delivered.
s3DestinationConfiguration_bucket :: Lens.Lens' S3DestinationConfiguration Prelude.Text
s3DestinationConfiguration_bucket :: (Text -> f Text)
-> S3DestinationConfiguration -> f S3DestinationConfiguration
s3DestinationConfiguration_bucket = (S3DestinationConfiguration -> Text)
-> (S3DestinationConfiguration
    -> Text -> S3DestinationConfiguration)
-> Lens
     S3DestinationConfiguration S3DestinationConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3DestinationConfiguration' {Text
bucket :: Text
$sel:bucket:S3DestinationConfiguration' :: S3DestinationConfiguration -> Text
bucket} -> Text
bucket) (\s :: S3DestinationConfiguration
s@S3DestinationConfiguration' {} Text
a -> S3DestinationConfiguration
s {$sel:bucket:S3DestinationConfiguration' :: Text
bucket = Text
a} :: S3DestinationConfiguration)

-- | The key of the dataset contents object in an S3 bucket. Each object has
-- a key that is a unique identifier. Each object has exactly one key.
--
-- You can create a unique key with the following options:
--
-- -   Use @!{iotanalytics:scheduleTime}@ to insert the time of a scheduled
--     SQL query run.
--
-- -   Use @!{iotanalytics:versionId}@ to insert a unique hash that
--     identifies a dataset content.
--
-- -   Use @!{iotanalytics:creationTime}@ to insert the creation time of a
--     dataset content.
--
-- The following example creates a unique key for a CSV file:
-- @dataset\/mydataset\/!{iotanalytics:scheduleTime}\/!{iotanalytics:versionId}.csv@
--
-- If you don\'t use @!{iotanalytics:versionId}@ to specify the key, you
-- might get duplicate keys. For example, you might have two dataset
-- contents with the same @scheduleTime@ but different @versionId@s. This
-- means that one dataset content overwrites the other.
s3DestinationConfiguration_key :: Lens.Lens' S3DestinationConfiguration Prelude.Text
s3DestinationConfiguration_key :: (Text -> f Text)
-> S3DestinationConfiguration -> f S3DestinationConfiguration
s3DestinationConfiguration_key = (S3DestinationConfiguration -> Text)
-> (S3DestinationConfiguration
    -> Text -> S3DestinationConfiguration)
-> Lens
     S3DestinationConfiguration S3DestinationConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3DestinationConfiguration' {Text
key :: Text
$sel:key:S3DestinationConfiguration' :: S3DestinationConfiguration -> Text
key} -> Text
key) (\s :: S3DestinationConfiguration
s@S3DestinationConfiguration' {} Text
a -> S3DestinationConfiguration
s {$sel:key:S3DestinationConfiguration' :: Text
key = Text
a} :: S3DestinationConfiguration)

-- | The ARN of the role that grants IoT Analytics permission to interact
-- with your Amazon S3 and Glue resources.
s3DestinationConfiguration_roleArn :: Lens.Lens' S3DestinationConfiguration Prelude.Text
s3DestinationConfiguration_roleArn :: (Text -> f Text)
-> S3DestinationConfiguration -> f S3DestinationConfiguration
s3DestinationConfiguration_roleArn = (S3DestinationConfiguration -> Text)
-> (S3DestinationConfiguration
    -> Text -> S3DestinationConfiguration)
-> Lens
     S3DestinationConfiguration S3DestinationConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3DestinationConfiguration' {Text
roleArn :: Text
$sel:roleArn:S3DestinationConfiguration' :: S3DestinationConfiguration -> Text
roleArn} -> Text
roleArn) (\s :: S3DestinationConfiguration
s@S3DestinationConfiguration' {} Text
a -> S3DestinationConfiguration
s {$sel:roleArn:S3DestinationConfiguration' :: Text
roleArn = Text
a} :: S3DestinationConfiguration)

instance Core.FromJSON S3DestinationConfiguration where
  parseJSON :: Value -> Parser S3DestinationConfiguration
parseJSON =
    String
-> (Object -> Parser S3DestinationConfiguration)
-> Value
-> Parser S3DestinationConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"S3DestinationConfiguration"
      ( \Object
x ->
          Maybe GlueConfiguration
-> Text -> Text -> Text -> S3DestinationConfiguration
S3DestinationConfiguration'
            (Maybe GlueConfiguration
 -> Text -> Text -> Text -> S3DestinationConfiguration)
-> Parser (Maybe GlueConfiguration)
-> Parser (Text -> Text -> Text -> S3DestinationConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe GlueConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"glueConfiguration")
            Parser (Text -> Text -> Text -> S3DestinationConfiguration)
-> Parser Text
-> Parser (Text -> Text -> S3DestinationConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"bucket")
            Parser (Text -> Text -> S3DestinationConfiguration)
-> Parser Text -> Parser (Text -> S3DestinationConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"key")
            Parser (Text -> S3DestinationConfiguration)
-> Parser Text -> Parser S3DestinationConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"roleArn")
      )

instance Prelude.Hashable S3DestinationConfiguration

instance Prelude.NFData S3DestinationConfiguration

instance Core.ToJSON S3DestinationConfiguration where
  toJSON :: S3DestinationConfiguration -> Value
toJSON S3DestinationConfiguration' {Maybe GlueConfiguration
Text
roleArn :: Text
key :: Text
bucket :: Text
glueConfiguration :: Maybe GlueConfiguration
$sel:roleArn:S3DestinationConfiguration' :: S3DestinationConfiguration -> Text
$sel:key:S3DestinationConfiguration' :: S3DestinationConfiguration -> Text
$sel:bucket:S3DestinationConfiguration' :: S3DestinationConfiguration -> Text
$sel:glueConfiguration:S3DestinationConfiguration' :: S3DestinationConfiguration -> Maybe GlueConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"glueConfiguration" Text -> GlueConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (GlueConfiguration -> Pair)
-> Maybe GlueConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe GlueConfiguration
glueConfiguration,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"bucket" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
bucket),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
key),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn)
          ]
      )