{-# 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.Transfer.Types.S3InputFileLocation
-- 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.Transfer.Types.S3InputFileLocation where

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

-- | Specifies the customer input S3 file location. If it is used inside
-- @copyStepDetails.DestinationFileLocation@, it should be the S3 copy
-- destination.
--
-- You need to provide the bucket and key. The key can represent either a
-- path or a file. This is determined by whether or not you end the key
-- value with the forward slash (\/) character. If the final character is
-- \"\/\", then your file is copied to the folder, and its name does not
-- change. If, rather, the final character is alphanumeric, your uploaded
-- file is renamed to the path value. In this case, if a file with that
-- name already exists, it is overwritten.
--
-- For example, if your path is @shared-files\/bob\/@, your uploaded files
-- are copied to the @shared-files\/bob\/@, folder. If your path is
-- @shared-files\/today@, each uploaded file is copied to the
-- @shared-files@ folder and named @today@: each upload overwrites the
-- previous version of the /bob/ file.
--
-- /See:/ 'newS3InputFileLocation' smart constructor.
data S3InputFileLocation = S3InputFileLocation'
  { -- | Specifies the S3 bucket for the customer input file.
    S3InputFileLocation -> Maybe Text
bucket :: Prelude.Maybe Prelude.Text,
    -- | The name assigned to the file when it was created in S3. You use the
    -- object key to retrieve the object.
    S3InputFileLocation -> Maybe Text
key :: Prelude.Maybe Prelude.Text
  }
  deriving (S3InputFileLocation -> S3InputFileLocation -> Bool
(S3InputFileLocation -> S3InputFileLocation -> Bool)
-> (S3InputFileLocation -> S3InputFileLocation -> Bool)
-> Eq S3InputFileLocation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: S3InputFileLocation -> S3InputFileLocation -> Bool
$c/= :: S3InputFileLocation -> S3InputFileLocation -> Bool
== :: S3InputFileLocation -> S3InputFileLocation -> Bool
$c== :: S3InputFileLocation -> S3InputFileLocation -> Bool
Prelude.Eq, ReadPrec [S3InputFileLocation]
ReadPrec S3InputFileLocation
Int -> ReadS S3InputFileLocation
ReadS [S3InputFileLocation]
(Int -> ReadS S3InputFileLocation)
-> ReadS [S3InputFileLocation]
-> ReadPrec S3InputFileLocation
-> ReadPrec [S3InputFileLocation]
-> Read S3InputFileLocation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [S3InputFileLocation]
$creadListPrec :: ReadPrec [S3InputFileLocation]
readPrec :: ReadPrec S3InputFileLocation
$creadPrec :: ReadPrec S3InputFileLocation
readList :: ReadS [S3InputFileLocation]
$creadList :: ReadS [S3InputFileLocation]
readsPrec :: Int -> ReadS S3InputFileLocation
$creadsPrec :: Int -> ReadS S3InputFileLocation
Prelude.Read, Int -> S3InputFileLocation -> ShowS
[S3InputFileLocation] -> ShowS
S3InputFileLocation -> String
(Int -> S3InputFileLocation -> ShowS)
-> (S3InputFileLocation -> String)
-> ([S3InputFileLocation] -> ShowS)
-> Show S3InputFileLocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [S3InputFileLocation] -> ShowS
$cshowList :: [S3InputFileLocation] -> ShowS
show :: S3InputFileLocation -> String
$cshow :: S3InputFileLocation -> String
showsPrec :: Int -> S3InputFileLocation -> ShowS
$cshowsPrec :: Int -> S3InputFileLocation -> ShowS
Prelude.Show, (forall x. S3InputFileLocation -> Rep S3InputFileLocation x)
-> (forall x. Rep S3InputFileLocation x -> S3InputFileLocation)
-> Generic S3InputFileLocation
forall x. Rep S3InputFileLocation x -> S3InputFileLocation
forall x. S3InputFileLocation -> Rep S3InputFileLocation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep S3InputFileLocation x -> S3InputFileLocation
$cfrom :: forall x. S3InputFileLocation -> Rep S3InputFileLocation x
Prelude.Generic)

-- |
-- Create a value of 'S3InputFileLocation' 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:
--
-- 'bucket', 's3InputFileLocation_bucket' - Specifies the S3 bucket for the customer input file.
--
-- 'key', 's3InputFileLocation_key' - The name assigned to the file when it was created in S3. You use the
-- object key to retrieve the object.
newS3InputFileLocation ::
  S3InputFileLocation
newS3InputFileLocation :: S3InputFileLocation
newS3InputFileLocation =
  S3InputFileLocation' :: Maybe Text -> Maybe Text -> S3InputFileLocation
S3InputFileLocation'
    { $sel:bucket:S3InputFileLocation' :: Maybe Text
bucket = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:key:S3InputFileLocation' :: Maybe Text
key = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the S3 bucket for the customer input file.
s3InputFileLocation_bucket :: Lens.Lens' S3InputFileLocation (Prelude.Maybe Prelude.Text)
s3InputFileLocation_bucket :: (Maybe Text -> f (Maybe Text))
-> S3InputFileLocation -> f S3InputFileLocation
s3InputFileLocation_bucket = (S3InputFileLocation -> Maybe Text)
-> (S3InputFileLocation -> Maybe Text -> S3InputFileLocation)
-> Lens
     S3InputFileLocation S3InputFileLocation (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3InputFileLocation' {Maybe Text
bucket :: Maybe Text
$sel:bucket:S3InputFileLocation' :: S3InputFileLocation -> Maybe Text
bucket} -> Maybe Text
bucket) (\s :: S3InputFileLocation
s@S3InputFileLocation' {} Maybe Text
a -> S3InputFileLocation
s {$sel:bucket:S3InputFileLocation' :: Maybe Text
bucket = Maybe Text
a} :: S3InputFileLocation)

-- | The name assigned to the file when it was created in S3. You use the
-- object key to retrieve the object.
s3InputFileLocation_key :: Lens.Lens' S3InputFileLocation (Prelude.Maybe Prelude.Text)
s3InputFileLocation_key :: (Maybe Text -> f (Maybe Text))
-> S3InputFileLocation -> f S3InputFileLocation
s3InputFileLocation_key = (S3InputFileLocation -> Maybe Text)
-> (S3InputFileLocation -> Maybe Text -> S3InputFileLocation)
-> Lens
     S3InputFileLocation S3InputFileLocation (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3InputFileLocation' {Maybe Text
key :: Maybe Text
$sel:key:S3InputFileLocation' :: S3InputFileLocation -> Maybe Text
key} -> Maybe Text
key) (\s :: S3InputFileLocation
s@S3InputFileLocation' {} Maybe Text
a -> S3InputFileLocation
s {$sel:key:S3InputFileLocation' :: Maybe Text
key = Maybe Text
a} :: S3InputFileLocation)

instance Core.FromJSON S3InputFileLocation where
  parseJSON :: Value -> Parser S3InputFileLocation
parseJSON =
    String
-> (Object -> Parser S3InputFileLocation)
-> Value
-> Parser S3InputFileLocation
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"S3InputFileLocation"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> S3InputFileLocation
S3InputFileLocation'
            (Maybe Text -> Maybe Text -> S3InputFileLocation)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> S3InputFileLocation)
forall (f :: * -> *) a b. Functor 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
"Bucket") Parser (Maybe Text -> S3InputFileLocation)
-> Parser (Maybe Text) -> Parser S3InputFileLocation
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
"Key")
      )

instance Prelude.Hashable S3InputFileLocation

instance Prelude.NFData S3InputFileLocation

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