{-# 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.S3.Types.Object
-- 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.S3.Types.Object where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.S3.Internal
import Amazonka.S3.Types.ObjectStorageClass
import Amazonka.S3.Types.Owner

-- | An object consists of data and its descriptive metadata.
--
-- /See:/ 'newObject' smart constructor.
data Object = Object'
  { -- | The owner of the object
    Object -> Maybe Owner
owner :: Prelude.Maybe Owner,
    -- | The entity tag is a hash of the object. The ETag reflects changes only
    -- to the contents of an object, not its metadata. The ETag may or may not
    -- be an MD5 digest of the object data. Whether or not it is depends on how
    -- the object was created and how it is encrypted as described below:
    --
    -- -   Objects created by the PUT Object, POST Object, or Copy operation,
    --     or through the Amazon Web Services Management Console, and are
    --     encrypted by SSE-S3 or plaintext, have ETags that are an MD5 digest
    --     of their object data.
    --
    -- -   Objects created by the PUT Object, POST Object, or Copy operation,
    --     or through the Amazon Web Services Management Console, and are
    --     encrypted by SSE-C or SSE-KMS, have ETags that are not an MD5 digest
    --     of their object data.
    --
    -- -   If an object is created by either the Multipart Upload or Part Copy
    --     operation, the ETag is not an MD5 digest, regardless of the method
    --     of encryption.
    Object -> ETag
eTag :: ETag,
    -- | Size in bytes of the object
    Object -> Integer
size :: Prelude.Integer,
    -- | The name that you assign to an object. You use the object key to
    -- retrieve the object.
    Object -> ObjectKey
key :: ObjectKey,
    -- | The class of storage used to store the object.
    Object -> ObjectStorageClass
storageClass :: ObjectStorageClass,
    -- | Creation date of the object.
    Object -> ISO8601
lastModified :: Core.ISO8601
  }
  deriving (Object -> Object -> Bool
(Object -> Object -> Bool)
-> (Object -> Object -> Bool) -> Eq Object
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Object -> Object -> Bool
$c/= :: Object -> Object -> Bool
== :: Object -> Object -> Bool
$c== :: Object -> Object -> Bool
Prelude.Eq, ReadPrec [Object]
ReadPrec Object
Int -> ReadS Object
ReadS [Object]
(Int -> ReadS Object)
-> ReadS [Object]
-> ReadPrec Object
-> ReadPrec [Object]
-> Read Object
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Object]
$creadListPrec :: ReadPrec [Object]
readPrec :: ReadPrec Object
$creadPrec :: ReadPrec Object
readList :: ReadS [Object]
$creadList :: ReadS [Object]
readsPrec :: Int -> ReadS Object
$creadsPrec :: Int -> ReadS Object
Prelude.Read, Int -> Object -> ShowS
[Object] -> ShowS
Object -> String
(Int -> Object -> ShowS)
-> (Object -> String) -> ([Object] -> ShowS) -> Show Object
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Object] -> ShowS
$cshowList :: [Object] -> ShowS
show :: Object -> String
$cshow :: Object -> String
showsPrec :: Int -> Object -> ShowS
$cshowsPrec :: Int -> Object -> ShowS
Prelude.Show, (forall x. Object -> Rep Object x)
-> (forall x. Rep Object x -> Object) -> Generic Object
forall x. Rep Object x -> Object
forall x. Object -> Rep Object x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Object x -> Object
$cfrom :: forall x. Object -> Rep Object x
Prelude.Generic)

-- |
-- Create a value of 'Object' 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:
--
-- 'owner', 'object_owner' - The owner of the object
--
-- 'eTag', 'object_eTag' - The entity tag is a hash of the object. The ETag reflects changes only
-- to the contents of an object, not its metadata. The ETag may or may not
-- be an MD5 digest of the object data. Whether or not it is depends on how
-- the object was created and how it is encrypted as described below:
--
-- -   Objects created by the PUT Object, POST Object, or Copy operation,
--     or through the Amazon Web Services Management Console, and are
--     encrypted by SSE-S3 or plaintext, have ETags that are an MD5 digest
--     of their object data.
--
-- -   Objects created by the PUT Object, POST Object, or Copy operation,
--     or through the Amazon Web Services Management Console, and are
--     encrypted by SSE-C or SSE-KMS, have ETags that are not an MD5 digest
--     of their object data.
--
-- -   If an object is created by either the Multipart Upload or Part Copy
--     operation, the ETag is not an MD5 digest, regardless of the method
--     of encryption.
--
-- 'size', 'object_size' - Size in bytes of the object
--
-- 'key', 'object_key' - The name that you assign to an object. You use the object key to
-- retrieve the object.
--
-- 'storageClass', 'object_storageClass' - The class of storage used to store the object.
--
-- 'lastModified', 'object_lastModified' - Creation date of the object.
newObject ::
  -- | 'eTag'
  ETag ->
  -- | 'size'
  Prelude.Integer ->
  -- | 'key'
  ObjectKey ->
  -- | 'storageClass'
  ObjectStorageClass ->
  -- | 'lastModified'
  Prelude.UTCTime ->
  Object
newObject :: ETag
-> Integer -> ObjectKey -> ObjectStorageClass -> UTCTime -> Object
newObject
  ETag
pETag_
  Integer
pSize_
  ObjectKey
pKey_
  ObjectStorageClass
pStorageClass_
  UTCTime
pLastModified_ =
    Object' :: Maybe Owner
-> ETag
-> Integer
-> ObjectKey
-> ObjectStorageClass
-> ISO8601
-> Object
Object'
      { $sel:owner:Object' :: Maybe Owner
owner = Maybe Owner
forall a. Maybe a
Prelude.Nothing,
        $sel:eTag:Object' :: ETag
eTag = ETag
pETag_,
        $sel:size:Object' :: Integer
size = Integer
pSize_,
        $sel:key:Object' :: ObjectKey
key = ObjectKey
pKey_,
        $sel:storageClass:Object' :: ObjectStorageClass
storageClass = ObjectStorageClass
pStorageClass_,
        $sel:lastModified:Object' :: ISO8601
lastModified = Tagged UTCTime (Identity UTCTime)
-> Tagged ISO8601 (Identity ISO8601)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged ISO8601 (Identity ISO8601))
-> UTCTime -> ISO8601
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pLastModified_
      }

-- | The owner of the object
object_owner :: Lens.Lens' Object (Prelude.Maybe Owner)
object_owner :: (Maybe Owner -> f (Maybe Owner)) -> Object -> f Object
object_owner = (Object -> Maybe Owner)
-> (Object -> Maybe Owner -> Object)
-> Lens Object Object (Maybe Owner) (Maybe Owner)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Object' {Maybe Owner
owner :: Maybe Owner
$sel:owner:Object' :: Object -> Maybe Owner
owner} -> Maybe Owner
owner) (\s :: Object
s@Object' {} Maybe Owner
a -> Object
s {$sel:owner:Object' :: Maybe Owner
owner = Maybe Owner
a} :: Object)

-- | The entity tag is a hash of the object. The ETag reflects changes only
-- to the contents of an object, not its metadata. The ETag may or may not
-- be an MD5 digest of the object data. Whether or not it is depends on how
-- the object was created and how it is encrypted as described below:
--
-- -   Objects created by the PUT Object, POST Object, or Copy operation,
--     or through the Amazon Web Services Management Console, and are
--     encrypted by SSE-S3 or plaintext, have ETags that are an MD5 digest
--     of their object data.
--
-- -   Objects created by the PUT Object, POST Object, or Copy operation,
--     or through the Amazon Web Services Management Console, and are
--     encrypted by SSE-C or SSE-KMS, have ETags that are not an MD5 digest
--     of their object data.
--
-- -   If an object is created by either the Multipart Upload or Part Copy
--     operation, the ETag is not an MD5 digest, regardless of the method
--     of encryption.
object_eTag :: Lens.Lens' Object ETag
object_eTag :: (ETag -> f ETag) -> Object -> f Object
object_eTag = (Object -> ETag)
-> (Object -> ETag -> Object) -> Lens Object Object ETag ETag
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Object' {ETag
eTag :: ETag
$sel:eTag:Object' :: Object -> ETag
eTag} -> ETag
eTag) (\s :: Object
s@Object' {} ETag
a -> Object
s {$sel:eTag:Object' :: ETag
eTag = ETag
a} :: Object)

-- | Size in bytes of the object
object_size :: Lens.Lens' Object Prelude.Integer
object_size :: (Integer -> f Integer) -> Object -> f Object
object_size = (Object -> Integer)
-> (Object -> Integer -> Object)
-> Lens Object Object Integer Integer
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Object' {Integer
size :: Integer
$sel:size:Object' :: Object -> Integer
size} -> Integer
size) (\s :: Object
s@Object' {} Integer
a -> Object
s {$sel:size:Object' :: Integer
size = Integer
a} :: Object)

-- | The name that you assign to an object. You use the object key to
-- retrieve the object.
object_key :: Lens.Lens' Object ObjectKey
object_key :: (ObjectKey -> f ObjectKey) -> Object -> f Object
object_key = (Object -> ObjectKey)
-> (Object -> ObjectKey -> Object)
-> Lens Object Object ObjectKey ObjectKey
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Object' {ObjectKey
key :: ObjectKey
$sel:key:Object' :: Object -> ObjectKey
key} -> ObjectKey
key) (\s :: Object
s@Object' {} ObjectKey
a -> Object
s {$sel:key:Object' :: ObjectKey
key = ObjectKey
a} :: Object)

-- | The class of storage used to store the object.
object_storageClass :: Lens.Lens' Object ObjectStorageClass
object_storageClass :: (ObjectStorageClass -> f ObjectStorageClass) -> Object -> f Object
object_storageClass = (Object -> ObjectStorageClass)
-> (Object -> ObjectStorageClass -> Object)
-> Lens Object Object ObjectStorageClass ObjectStorageClass
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Object' {ObjectStorageClass
storageClass :: ObjectStorageClass
$sel:storageClass:Object' :: Object -> ObjectStorageClass
storageClass} -> ObjectStorageClass
storageClass) (\s :: Object
s@Object' {} ObjectStorageClass
a -> Object
s {$sel:storageClass:Object' :: ObjectStorageClass
storageClass = ObjectStorageClass
a} :: Object)

-- | Creation date of the object.
object_lastModified :: Lens.Lens' Object Prelude.UTCTime
object_lastModified :: (UTCTime -> f UTCTime) -> Object -> f Object
object_lastModified = (Object -> ISO8601)
-> (Object -> ISO8601 -> Object)
-> Lens Object Object ISO8601 ISO8601
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Object' {ISO8601
lastModified :: ISO8601
$sel:lastModified:Object' :: Object -> ISO8601
lastModified} -> ISO8601
lastModified) (\s :: Object
s@Object' {} ISO8601
a -> Object
s {$sel:lastModified:Object' :: ISO8601
lastModified = ISO8601
a} :: Object) ((ISO8601 -> f ISO8601) -> Object -> f Object)
-> ((UTCTime -> f UTCTime) -> ISO8601 -> f ISO8601)
-> (UTCTime -> f UTCTime)
-> Object
-> f Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> ISO8601 -> f ISO8601
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Core.FromXML Object where
  parseXML :: [Node] -> Either String Object
parseXML [Node]
x =
    Maybe Owner
-> ETag
-> Integer
-> ObjectKey
-> ObjectStorageClass
-> ISO8601
-> Object
Object'
      (Maybe Owner
 -> ETag
 -> Integer
 -> ObjectKey
 -> ObjectStorageClass
 -> ISO8601
 -> Object)
-> Either String (Maybe Owner)
-> Either
     String
     (ETag
      -> Integer -> ObjectKey -> ObjectStorageClass -> ISO8601 -> Object)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Owner)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Owner")
      Either
  String
  (ETag
   -> Integer -> ObjectKey -> ObjectStorageClass -> ISO8601 -> Object)
-> Either String ETag
-> Either
     String
     (Integer -> ObjectKey -> ObjectStorageClass -> ISO8601 -> Object)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String ETag
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"ETag")
      Either
  String
  (Integer -> ObjectKey -> ObjectStorageClass -> ISO8601 -> Object)
-> Either String Integer
-> Either
     String (ObjectKey -> ObjectStorageClass -> ISO8601 -> Object)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Integer
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Size")
      Either
  String (ObjectKey -> ObjectStorageClass -> ISO8601 -> Object)
-> Either String ObjectKey
-> Either String (ObjectStorageClass -> ISO8601 -> Object)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String ObjectKey
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Key")
      Either String (ObjectStorageClass -> ISO8601 -> Object)
-> Either String ObjectStorageClass
-> Either String (ISO8601 -> Object)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String ObjectStorageClass
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"StorageClass")
      Either String (ISO8601 -> Object)
-> Either String ISO8601 -> Either String Object
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String ISO8601
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"LastModified")

instance Prelude.Hashable Object

instance Prelude.NFData Object