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

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

-- | Information about an S3 object.
--
-- /See:/ 'newS3Object' smart constructor.
data S3Object = S3Object'
  { -- | The etag of the object.
    S3Object -> Maybe Text
etag :: Prelude.Maybe Prelude.Text,
    -- | The bucket containing the object.
    S3Object -> Text
bucket :: Prelude.Text,
    -- | The key of the object.
    S3Object -> Text
key :: 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:
--
-- 'etag', 's3Object_etag' - The etag of the object.
--
-- 'bucket', 's3Object_bucket' - The bucket containing the object.
--
-- 'key', 's3Object_key' - The key of the object.
newS3Object ::
  -- | 'bucket'
  Prelude.Text ->
  -- | 'key'
  Prelude.Text ->
  S3Object
newS3Object :: Text -> Text -> S3Object
newS3Object Text
pBucket_ Text
pKey_ =
  S3Object' :: Maybe Text -> Text -> Text -> S3Object
S3Object'
    { $sel:etag:S3Object' :: Maybe Text
etag = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bucket:S3Object' :: Text
bucket = Text
pBucket_,
      $sel:key:S3Object' :: Text
key = Text
pKey_
    }

-- | The etag of the object.
s3Object_etag :: Lens.Lens' S3Object (Prelude.Maybe Prelude.Text)
s3Object_etag :: (Maybe Text -> f (Maybe Text)) -> S3Object -> f S3Object
s3Object_etag = (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
etag :: Maybe Text
$sel:etag:S3Object' :: S3Object -> Maybe Text
etag} -> Maybe Text
etag) (\s :: S3Object
s@S3Object' {} Maybe Text
a -> S3Object
s {$sel:etag:S3Object' :: Maybe Text
etag = Maybe Text
a} :: S3Object)

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

-- | The key of the object.
s3Object_key :: Lens.Lens' S3Object Prelude.Text
s3Object_key :: (Text -> f Text) -> S3Object -> f S3Object
s3Object_key = (S3Object -> Text)
-> (S3Object -> Text -> S3Object)
-> Lens S3Object S3Object Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3Object' {Text
key :: Text
$sel:key:S3Object' :: S3Object -> Text
key} -> Text
key) (\s :: S3Object
s@S3Object' {} Text
a -> S3Object
s {$sel:key:S3Object' :: Text
key = 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 -> Text -> Text -> S3Object
S3Object'
            (Maybe Text -> Text -> Text -> S3Object)
-> Parser (Maybe Text) -> Parser (Text -> 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
"etag")
            Parser (Text -> Text -> S3Object)
-> Parser Text -> Parser (Text -> S3Object)
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 -> S3Object) -> Parser Text -> Parser S3Object
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")
      )

instance Prelude.Hashable S3Object

instance Prelude.NFData S3Object

instance Core.ToJSON S3Object where
  toJSON :: S3Object -> Value
toJSON S3Object' {Maybe Text
Text
key :: Text
bucket :: Text
etag :: Maybe Text
$sel:key:S3Object' :: S3Object -> Text
$sel:bucket:S3Object' :: S3Object -> Text
$sel:etag:S3Object' :: S3Object -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"etag" 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
etag,
            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)
          ]
      )