{-# 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.Rekognition.Types.S3Object
-- 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.Rekognition.Types.S3Object where

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

-- | Provides the S3 bucket name and object name.
--
-- The region for the S3 bucket containing the S3 object must match the
-- region you use for Amazon Rekognition operations.
--
-- For Amazon Rekognition to process an S3 object, the user must have
-- permission to access the S3 object. For more information, see
-- Resource-Based Policies in the Amazon Rekognition Developer Guide.
--
-- /See:/ 'newS3Object' smart constructor.
data S3Object = S3Object'
  { -- | Name of the S3 bucket.
    S3Object -> Maybe Text
bucket :: Prelude.Maybe Prelude.Text,
    -- | S3 object key name.
    S3Object -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | If the bucket is versioning enabled, you can specify the object version.
    S3Object -> Maybe Text
version :: Prelude.Maybe Prelude.Text
  }
  deriving (S3Object -> S3Object -> Bool
(S3Object -> S3Object -> Bool)
-> (S3Object -> S3Object -> Bool) -> Eq S3Object
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: S3Object -> S3Object -> Bool
$c/= :: S3Object -> S3Object -> Bool
== :: S3Object -> S3Object -> Bool
$c== :: S3Object -> S3Object -> Bool
Prelude.Eq, ReadPrec [S3Object]
ReadPrec S3Object
Int -> ReadS S3Object
ReadS [S3Object]
(Int -> ReadS S3Object)
-> ReadS [S3Object]
-> ReadPrec S3Object
-> ReadPrec [S3Object]
-> Read S3Object
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [S3Object]
$creadListPrec :: ReadPrec [S3Object]
readPrec :: ReadPrec S3Object
$creadPrec :: ReadPrec S3Object
readList :: ReadS [S3Object]
$creadList :: ReadS [S3Object]
readsPrec :: Int -> ReadS S3Object
$creadsPrec :: Int -> ReadS S3Object
Prelude.Read, Int -> S3Object -> ShowS
[S3Object] -> ShowS
S3Object -> String
(Int -> S3Object -> ShowS)
-> (S3Object -> String) -> ([S3Object] -> ShowS) -> Show S3Object
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [S3Object] -> ShowS
$cshowList :: [S3Object] -> ShowS
show :: S3Object -> String
$cshow :: S3Object -> String
showsPrec :: Int -> S3Object -> ShowS
$cshowsPrec :: Int -> S3Object -> ShowS
Prelude.Show, (forall x. S3Object -> Rep S3Object x)
-> (forall x. Rep S3Object x -> S3Object) -> Generic S3Object
forall x. Rep S3Object x -> S3Object
forall x. S3Object -> Rep S3Object x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep S3Object x -> S3Object
$cfrom :: forall x. S3Object -> Rep S3Object x
Prelude.Generic)

-- |
-- Create a value of 'S3Object' 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', 's3Object_bucket' - Name of the S3 bucket.
--
-- 'name', 's3Object_name' - S3 object key name.
--
-- 'version', 's3Object_version' - If the bucket is versioning enabled, you can specify the object version.
newS3Object ::
  S3Object
newS3Object :: S3Object
newS3Object =
  S3Object' :: Maybe Text -> Maybe Text -> Maybe Text -> S3Object
S3Object'
    { $sel:bucket:S3Object' :: Maybe Text
bucket = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:S3Object' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:version:S3Object' :: Maybe Text
version = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Name of the S3 bucket.
s3Object_bucket :: Lens.Lens' S3Object (Prelude.Maybe Prelude.Text)
s3Object_bucket :: (Maybe Text -> f (Maybe Text)) -> S3Object -> f S3Object
s3Object_bucket = (S3Object -> Maybe Text)
-> (S3Object -> Maybe Text -> S3Object)
-> Lens S3Object S3Object (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Object' {Maybe Text
bucket :: Maybe Text
$sel:bucket:S3Object' :: S3Object -> Maybe Text
bucket} -> Maybe Text
bucket) (\s :: S3Object
s@S3Object' {} Maybe Text
a -> S3Object
s {$sel:bucket:S3Object' :: Maybe Text
bucket = Maybe Text
a} :: S3Object)

-- | S3 object key name.
s3Object_name :: Lens.Lens' S3Object (Prelude.Maybe Prelude.Text)
s3Object_name :: (Maybe Text -> f (Maybe Text)) -> S3Object -> f S3Object
s3Object_name = (S3Object -> Maybe Text)
-> (S3Object -> Maybe Text -> S3Object)
-> Lens S3Object S3Object (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Object' {Maybe Text
name :: Maybe Text
$sel:name:S3Object' :: S3Object -> Maybe Text
name} -> Maybe Text
name) (\s :: S3Object
s@S3Object' {} Maybe Text
a -> S3Object
s {$sel:name:S3Object' :: Maybe Text
name = Maybe Text
a} :: S3Object)

-- | If the bucket is versioning enabled, you can specify the object version.
s3Object_version :: Lens.Lens' S3Object (Prelude.Maybe Prelude.Text)
s3Object_version :: (Maybe Text -> f (Maybe Text)) -> S3Object -> f S3Object
s3Object_version = (S3Object -> Maybe Text)
-> (S3Object -> Maybe Text -> S3Object)
-> Lens S3Object S3Object (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Object' {Maybe Text
version :: Maybe Text
$sel:version:S3Object' :: S3Object -> Maybe Text
version} -> Maybe Text
version) (\s :: S3Object
s@S3Object' {} Maybe Text
a -> S3Object
s {$sel:version:S3Object' :: Maybe Text
version = Maybe Text
a} :: S3Object)

instance Core.FromJSON S3Object where
  parseJSON :: Value -> Parser S3Object
parseJSON =
    String -> (Object -> Parser S3Object) -> Value -> Parser S3Object
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"S3Object"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe Text -> S3Object
S3Object'
            (Maybe Text -> Maybe Text -> Maybe Text -> S3Object)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> S3Object)
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 -> Maybe Text -> S3Object)
-> Parser (Maybe Text) -> Parser (Maybe Text -> S3Object)
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
"Name")
            Parser (Maybe Text -> S3Object)
-> Parser (Maybe Text) -> Parser S3Object
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
"Version")
      )

instance Prelude.Hashable S3Object

instance Prelude.NFData S3Object

instance Core.ToJSON S3Object where
  toJSON :: S3Object -> Value
toJSON S3Object' {Maybe Text
version :: Maybe Text
name :: Maybe Text
bucket :: Maybe Text
$sel:version:S3Object' :: S3Object -> Maybe Text
$sel:name:S3Object' :: S3Object -> Maybe Text
$sel:bucket:S3Object' :: S3Object -> 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
"Name" 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
name,
            (Text
"Version" 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
version
          ]
      )