{-# 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.Forecast.Types.S3Config
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Forecast.Types.S3Config where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | The path to the file(s) in an Amazon Simple Storage Service (Amazon S3)
-- bucket, and an AWS Identity and Access Management (IAM) role that Amazon
-- Forecast can assume to access the file(s). Optionally, includes an AWS
-- Key Management Service (KMS) key. This object is part of the DataSource
-- object that is submitted in the CreateDatasetImportJob request, and part
-- of the DataDestination object.
--
-- /See:/ 'newS3Config' smart constructor.
data S3Config = S3Config'
  { -- | The Amazon Resource Name (ARN) of an AWS Key Management Service (KMS)
    -- key.
    S3Config -> Maybe Text
kmsKeyArn :: Prelude.Maybe Prelude.Text,
    -- | The path to an Amazon Simple Storage Service (Amazon S3) bucket or
    -- file(s) in an Amazon S3 bucket.
    S3Config -> Text
path :: Prelude.Text,
    -- | The ARN of the AWS Identity and Access Management (IAM) role that Amazon
    -- Forecast can assume to access the Amazon S3 bucket or files. If you
    -- provide a value for the @KMSKeyArn@ key, the role must allow access to
    -- the key.
    --
    -- Passing a role across AWS accounts is not allowed. If you pass a role
    -- that isn\'t in your account, you get an @InvalidInputException@ error.
    S3Config -> Text
roleArn :: Prelude.Text
  }
  deriving (S3Config -> S3Config -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: S3Config -> S3Config -> Bool
$c/= :: S3Config -> S3Config -> Bool
== :: S3Config -> S3Config -> Bool
$c== :: S3Config -> S3Config -> Bool
Prelude.Eq, ReadPrec [S3Config]
ReadPrec S3Config
Int -> ReadS S3Config
ReadS [S3Config]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [S3Config]
$creadListPrec :: ReadPrec [S3Config]
readPrec :: ReadPrec S3Config
$creadPrec :: ReadPrec S3Config
readList :: ReadS [S3Config]
$creadList :: ReadS [S3Config]
readsPrec :: Int -> ReadS S3Config
$creadsPrec :: Int -> ReadS S3Config
Prelude.Read, Int -> S3Config -> ShowS
[S3Config] -> ShowS
S3Config -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [S3Config] -> ShowS
$cshowList :: [S3Config] -> ShowS
show :: S3Config -> String
$cshow :: S3Config -> String
showsPrec :: Int -> S3Config -> ShowS
$cshowsPrec :: Int -> S3Config -> ShowS
Prelude.Show, forall x. Rep S3Config x -> S3Config
forall x. S3Config -> Rep S3Config x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep S3Config x -> S3Config
$cfrom :: forall x. S3Config -> Rep S3Config x
Prelude.Generic)

-- |
-- Create a value of 'S3Config' 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:
--
-- 'kmsKeyArn', 's3Config_kmsKeyArn' - The Amazon Resource Name (ARN) of an AWS Key Management Service (KMS)
-- key.
--
-- 'path', 's3Config_path' - The path to an Amazon Simple Storage Service (Amazon S3) bucket or
-- file(s) in an Amazon S3 bucket.
--
-- 'roleArn', 's3Config_roleArn' - The ARN of the AWS Identity and Access Management (IAM) role that Amazon
-- Forecast can assume to access the Amazon S3 bucket or files. If you
-- provide a value for the @KMSKeyArn@ key, the role must allow access to
-- the key.
--
-- Passing a role across AWS accounts is not allowed. If you pass a role
-- that isn\'t in your account, you get an @InvalidInputException@ error.
newS3Config ::
  -- | 'path'
  Prelude.Text ->
  -- | 'roleArn'
  Prelude.Text ->
  S3Config
newS3Config :: Text -> Text -> S3Config
newS3Config Text
pPath_ Text
pRoleArn_ =
  S3Config'
    { $sel:kmsKeyArn:S3Config' :: Maybe Text
kmsKeyArn = forall a. Maybe a
Prelude.Nothing,
      $sel:path:S3Config' :: Text
path = Text
pPath_,
      $sel:roleArn:S3Config' :: Text
roleArn = Text
pRoleArn_
    }

-- | The Amazon Resource Name (ARN) of an AWS Key Management Service (KMS)
-- key.
s3Config_kmsKeyArn :: Lens.Lens' S3Config (Prelude.Maybe Prelude.Text)
s3Config_kmsKeyArn :: Lens' S3Config (Maybe Text)
s3Config_kmsKeyArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Config' {Maybe Text
kmsKeyArn :: Maybe Text
$sel:kmsKeyArn:S3Config' :: S3Config -> Maybe Text
kmsKeyArn} -> Maybe Text
kmsKeyArn) (\s :: S3Config
s@S3Config' {} Maybe Text
a -> S3Config
s {$sel:kmsKeyArn:S3Config' :: Maybe Text
kmsKeyArn = Maybe Text
a} :: S3Config)

-- | The path to an Amazon Simple Storage Service (Amazon S3) bucket or
-- file(s) in an Amazon S3 bucket.
s3Config_path :: Lens.Lens' S3Config Prelude.Text
s3Config_path :: Lens' S3Config Text
s3Config_path = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Config' {Text
path :: Text
$sel:path:S3Config' :: S3Config -> Text
path} -> Text
path) (\s :: S3Config
s@S3Config' {} Text
a -> S3Config
s {$sel:path:S3Config' :: Text
path = Text
a} :: S3Config)

-- | The ARN of the AWS Identity and Access Management (IAM) role that Amazon
-- Forecast can assume to access the Amazon S3 bucket or files. If you
-- provide a value for the @KMSKeyArn@ key, the role must allow access to
-- the key.
--
-- Passing a role across AWS accounts is not allowed. If you pass a role
-- that isn\'t in your account, you get an @InvalidInputException@ error.
s3Config_roleArn :: Lens.Lens' S3Config Prelude.Text
s3Config_roleArn :: Lens' S3Config Text
s3Config_roleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Config' {Text
roleArn :: Text
$sel:roleArn:S3Config' :: S3Config -> Text
roleArn} -> Text
roleArn) (\s :: S3Config
s@S3Config' {} Text
a -> S3Config
s {$sel:roleArn:S3Config' :: Text
roleArn = Text
a} :: S3Config)

instance Data.FromJSON S3Config where
  parseJSON :: Value -> Parser S3Config
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"S3Config"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> S3Config
S3Config'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"KMSKeyArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Path")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"RoleArn")
      )

instance Prelude.Hashable S3Config where
  hashWithSalt :: Int -> S3Config -> Int
hashWithSalt Int
_salt S3Config' {Maybe Text
Text
roleArn :: Text
path :: Text
kmsKeyArn :: Maybe Text
$sel:roleArn:S3Config' :: S3Config -> Text
$sel:path:S3Config' :: S3Config -> Text
$sel:kmsKeyArn:S3Config' :: S3Config -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
kmsKeyArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
path
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn

instance Prelude.NFData S3Config where
  rnf :: S3Config -> ()
rnf S3Config' {Maybe Text
Text
roleArn :: Text
path :: Text
kmsKeyArn :: Maybe Text
$sel:roleArn:S3Config' :: S3Config -> Text
$sel:path:S3Config' :: S3Config -> Text
$sel:kmsKeyArn:S3Config' :: S3Config -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsKeyArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
path
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
roleArn

instance Data.ToJSON S3Config where
  toJSON :: S3Config -> Value
toJSON S3Config' {Maybe Text
Text
roleArn :: Text
path :: Text
kmsKeyArn :: Maybe Text
$sel:roleArn:S3Config' :: S3Config -> Text
$sel:path:S3Config' :: S3Config -> Text
$sel:kmsKeyArn:S3Config' :: S3Config -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"KMSKeyArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
kmsKeyArn,
            forall a. a -> Maybe a
Prelude.Just (Key
"Path" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
path),
            forall a. a -> Maybe a
Prelude.Just (Key
"RoleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
roleArn)
          ]
      )