{-# 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.Bucket
-- 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.Bucket where

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

-- | In terms of implementation, a Bucket is a resource. An Amazon S3 bucket
-- name is globally unique, and the namespace is shared by all Amazon Web
-- Services accounts.
--
-- /See:/ 'newBucket' smart constructor.
data Bucket = Bucket'
  { -- | Date the bucket was created. This date can change when making changes to
    -- your bucket, such as editing its bucket policy.
    Bucket -> ISO8601
creationDate :: Core.ISO8601,
    -- | The name of the bucket.
    Bucket -> BucketName
name :: BucketName
  }
  deriving (Bucket -> Bucket -> Bool
(Bucket -> Bucket -> Bool)
-> (Bucket -> Bucket -> Bool) -> Eq Bucket
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Bucket -> Bucket -> Bool
$c/= :: Bucket -> Bucket -> Bool
== :: Bucket -> Bucket -> Bool
$c== :: Bucket -> Bucket -> Bool
Prelude.Eq, ReadPrec [Bucket]
ReadPrec Bucket
Int -> ReadS Bucket
ReadS [Bucket]
(Int -> ReadS Bucket)
-> ReadS [Bucket]
-> ReadPrec Bucket
-> ReadPrec [Bucket]
-> Read Bucket
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Bucket]
$creadListPrec :: ReadPrec [Bucket]
readPrec :: ReadPrec Bucket
$creadPrec :: ReadPrec Bucket
readList :: ReadS [Bucket]
$creadList :: ReadS [Bucket]
readsPrec :: Int -> ReadS Bucket
$creadsPrec :: Int -> ReadS Bucket
Prelude.Read, Int -> Bucket -> ShowS
[Bucket] -> ShowS
Bucket -> String
(Int -> Bucket -> ShowS)
-> (Bucket -> String) -> ([Bucket] -> ShowS) -> Show Bucket
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Bucket] -> ShowS
$cshowList :: [Bucket] -> ShowS
show :: Bucket -> String
$cshow :: Bucket -> String
showsPrec :: Int -> Bucket -> ShowS
$cshowsPrec :: Int -> Bucket -> ShowS
Prelude.Show, (forall x. Bucket -> Rep Bucket x)
-> (forall x. Rep Bucket x -> Bucket) -> Generic Bucket
forall x. Rep Bucket x -> Bucket
forall x. Bucket -> Rep Bucket x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Bucket x -> Bucket
$cfrom :: forall x. Bucket -> Rep Bucket x
Prelude.Generic)

-- |
-- Create a value of 'Bucket' 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:
--
-- 'creationDate', 'bucket_creationDate' - Date the bucket was created. This date can change when making changes to
-- your bucket, such as editing its bucket policy.
--
-- 'name', 'bucket_name' - The name of the bucket.
newBucket ::
  -- | 'creationDate'
  Prelude.UTCTime ->
  -- | 'name'
  BucketName ->
  Bucket
newBucket :: UTCTime -> BucketName -> Bucket
newBucket UTCTime
pCreationDate_ BucketName
pName_ =
  Bucket' :: ISO8601 -> BucketName -> Bucket
Bucket'
    { $sel:creationDate:Bucket' :: ISO8601
creationDate =
        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
pCreationDate_,
      $sel:name:Bucket' :: BucketName
name = BucketName
pName_
    }

-- | Date the bucket was created. This date can change when making changes to
-- your bucket, such as editing its bucket policy.
bucket_creationDate :: Lens.Lens' Bucket Prelude.UTCTime
bucket_creationDate :: (UTCTime -> f UTCTime) -> Bucket -> f Bucket
bucket_creationDate = (Bucket -> ISO8601)
-> (Bucket -> ISO8601 -> Bucket)
-> Lens Bucket Bucket ISO8601 ISO8601
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Bucket' {ISO8601
creationDate :: ISO8601
$sel:creationDate:Bucket' :: Bucket -> ISO8601
creationDate} -> ISO8601
creationDate) (\s :: Bucket
s@Bucket' {} ISO8601
a -> Bucket
s {$sel:creationDate:Bucket' :: ISO8601
creationDate = ISO8601
a} :: Bucket) ((ISO8601 -> f ISO8601) -> Bucket -> f Bucket)
-> ((UTCTime -> f UTCTime) -> ISO8601 -> f ISO8601)
-> (UTCTime -> f UTCTime)
-> Bucket
-> f Bucket
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

-- | The name of the bucket.
bucket_name :: Lens.Lens' Bucket BucketName
bucket_name :: (BucketName -> f BucketName) -> Bucket -> f Bucket
bucket_name = (Bucket -> BucketName)
-> (Bucket -> BucketName -> Bucket)
-> Lens Bucket Bucket BucketName BucketName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Bucket' {BucketName
name :: BucketName
$sel:name:Bucket' :: Bucket -> BucketName
name} -> BucketName
name) (\s :: Bucket
s@Bucket' {} BucketName
a -> Bucket
s {$sel:name:Bucket' :: BucketName
name = BucketName
a} :: Bucket)

instance Core.FromXML Bucket where
  parseXML :: [Node] -> Either String Bucket
parseXML [Node]
x =
    ISO8601 -> BucketName -> Bucket
Bucket'
      (ISO8601 -> BucketName -> Bucket)
-> Either String ISO8601 -> Either String (BucketName -> Bucket)
forall (f :: * -> *) a b. Functor 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
"CreationDate")
      Either String (BucketName -> Bucket)
-> Either String BucketName -> Either String Bucket
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String BucketName
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Name")

instance Prelude.Hashable Bucket

instance Prelude.NFData Bucket