{-# 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.WebsiteConfiguration
-- 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.WebsiteConfiguration 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.ErrorDocument
import Amazonka.S3.Types.IndexDocument
import Amazonka.S3.Types.RedirectAllRequestsTo
import Amazonka.S3.Types.RoutingRule

-- | Specifies website configuration parameters for an Amazon S3 bucket.
--
-- /See:/ 'newWebsiteConfiguration' smart constructor.
data WebsiteConfiguration = WebsiteConfiguration'
  { -- | The redirect behavior for every request to this bucket\'s website
    -- endpoint.
    --
    -- If you specify this property, you can\'t specify any other property.
    WebsiteConfiguration -> Maybe RedirectAllRequestsTo
redirectAllRequestsTo :: Prelude.Maybe RedirectAllRequestsTo,
    -- | The name of the error document for the website.
    WebsiteConfiguration -> Maybe ErrorDocument
errorDocument :: Prelude.Maybe ErrorDocument,
    -- | The name of the index document for the website.
    WebsiteConfiguration -> Maybe IndexDocument
indexDocument :: Prelude.Maybe IndexDocument,
    -- | Rules that define when a redirect is applied and the redirect behavior.
    WebsiteConfiguration -> Maybe [RoutingRule]
routingRules :: Prelude.Maybe [RoutingRule]
  }
  deriving (WebsiteConfiguration -> WebsiteConfiguration -> Bool
(WebsiteConfiguration -> WebsiteConfiguration -> Bool)
-> (WebsiteConfiguration -> WebsiteConfiguration -> Bool)
-> Eq WebsiteConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WebsiteConfiguration -> WebsiteConfiguration -> Bool
$c/= :: WebsiteConfiguration -> WebsiteConfiguration -> Bool
== :: WebsiteConfiguration -> WebsiteConfiguration -> Bool
$c== :: WebsiteConfiguration -> WebsiteConfiguration -> Bool
Prelude.Eq, ReadPrec [WebsiteConfiguration]
ReadPrec WebsiteConfiguration
Int -> ReadS WebsiteConfiguration
ReadS [WebsiteConfiguration]
(Int -> ReadS WebsiteConfiguration)
-> ReadS [WebsiteConfiguration]
-> ReadPrec WebsiteConfiguration
-> ReadPrec [WebsiteConfiguration]
-> Read WebsiteConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [WebsiteConfiguration]
$creadListPrec :: ReadPrec [WebsiteConfiguration]
readPrec :: ReadPrec WebsiteConfiguration
$creadPrec :: ReadPrec WebsiteConfiguration
readList :: ReadS [WebsiteConfiguration]
$creadList :: ReadS [WebsiteConfiguration]
readsPrec :: Int -> ReadS WebsiteConfiguration
$creadsPrec :: Int -> ReadS WebsiteConfiguration
Prelude.Read, Int -> WebsiteConfiguration -> ShowS
[WebsiteConfiguration] -> ShowS
WebsiteConfiguration -> String
(Int -> WebsiteConfiguration -> ShowS)
-> (WebsiteConfiguration -> String)
-> ([WebsiteConfiguration] -> ShowS)
-> Show WebsiteConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WebsiteConfiguration] -> ShowS
$cshowList :: [WebsiteConfiguration] -> ShowS
show :: WebsiteConfiguration -> String
$cshow :: WebsiteConfiguration -> String
showsPrec :: Int -> WebsiteConfiguration -> ShowS
$cshowsPrec :: Int -> WebsiteConfiguration -> ShowS
Prelude.Show, (forall x. WebsiteConfiguration -> Rep WebsiteConfiguration x)
-> (forall x. Rep WebsiteConfiguration x -> WebsiteConfiguration)
-> Generic WebsiteConfiguration
forall x. Rep WebsiteConfiguration x -> WebsiteConfiguration
forall x. WebsiteConfiguration -> Rep WebsiteConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep WebsiteConfiguration x -> WebsiteConfiguration
$cfrom :: forall x. WebsiteConfiguration -> Rep WebsiteConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'WebsiteConfiguration' 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:
--
-- 'redirectAllRequestsTo', 'websiteConfiguration_redirectAllRequestsTo' - The redirect behavior for every request to this bucket\'s website
-- endpoint.
--
-- If you specify this property, you can\'t specify any other property.
--
-- 'errorDocument', 'websiteConfiguration_errorDocument' - The name of the error document for the website.
--
-- 'indexDocument', 'websiteConfiguration_indexDocument' - The name of the index document for the website.
--
-- 'routingRules', 'websiteConfiguration_routingRules' - Rules that define when a redirect is applied and the redirect behavior.
newWebsiteConfiguration ::
  WebsiteConfiguration
newWebsiteConfiguration :: WebsiteConfiguration
newWebsiteConfiguration =
  WebsiteConfiguration' :: Maybe RedirectAllRequestsTo
-> Maybe ErrorDocument
-> Maybe IndexDocument
-> Maybe [RoutingRule]
-> WebsiteConfiguration
WebsiteConfiguration'
    { $sel:redirectAllRequestsTo:WebsiteConfiguration' :: Maybe RedirectAllRequestsTo
redirectAllRequestsTo =
        Maybe RedirectAllRequestsTo
forall a. Maybe a
Prelude.Nothing,
      $sel:errorDocument:WebsiteConfiguration' :: Maybe ErrorDocument
errorDocument = Maybe ErrorDocument
forall a. Maybe a
Prelude.Nothing,
      $sel:indexDocument:WebsiteConfiguration' :: Maybe IndexDocument
indexDocument = Maybe IndexDocument
forall a. Maybe a
Prelude.Nothing,
      $sel:routingRules:WebsiteConfiguration' :: Maybe [RoutingRule]
routingRules = Maybe [RoutingRule]
forall a. Maybe a
Prelude.Nothing
    }

-- | The redirect behavior for every request to this bucket\'s website
-- endpoint.
--
-- If you specify this property, you can\'t specify any other property.
websiteConfiguration_redirectAllRequestsTo :: Lens.Lens' WebsiteConfiguration (Prelude.Maybe RedirectAllRequestsTo)
websiteConfiguration_redirectAllRequestsTo :: (Maybe RedirectAllRequestsTo -> f (Maybe RedirectAllRequestsTo))
-> WebsiteConfiguration -> f WebsiteConfiguration
websiteConfiguration_redirectAllRequestsTo = (WebsiteConfiguration -> Maybe RedirectAllRequestsTo)
-> (WebsiteConfiguration
    -> Maybe RedirectAllRequestsTo -> WebsiteConfiguration)
-> Lens
     WebsiteConfiguration
     WebsiteConfiguration
     (Maybe RedirectAllRequestsTo)
     (Maybe RedirectAllRequestsTo)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebsiteConfiguration' {Maybe RedirectAllRequestsTo
redirectAllRequestsTo :: Maybe RedirectAllRequestsTo
$sel:redirectAllRequestsTo:WebsiteConfiguration' :: WebsiteConfiguration -> Maybe RedirectAllRequestsTo
redirectAllRequestsTo} -> Maybe RedirectAllRequestsTo
redirectAllRequestsTo) (\s :: WebsiteConfiguration
s@WebsiteConfiguration' {} Maybe RedirectAllRequestsTo
a -> WebsiteConfiguration
s {$sel:redirectAllRequestsTo:WebsiteConfiguration' :: Maybe RedirectAllRequestsTo
redirectAllRequestsTo = Maybe RedirectAllRequestsTo
a} :: WebsiteConfiguration)

-- | The name of the error document for the website.
websiteConfiguration_errorDocument :: Lens.Lens' WebsiteConfiguration (Prelude.Maybe ErrorDocument)
websiteConfiguration_errorDocument :: (Maybe ErrorDocument -> f (Maybe ErrorDocument))
-> WebsiteConfiguration -> f WebsiteConfiguration
websiteConfiguration_errorDocument = (WebsiteConfiguration -> Maybe ErrorDocument)
-> (WebsiteConfiguration
    -> Maybe ErrorDocument -> WebsiteConfiguration)
-> Lens
     WebsiteConfiguration
     WebsiteConfiguration
     (Maybe ErrorDocument)
     (Maybe ErrorDocument)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebsiteConfiguration' {Maybe ErrorDocument
errorDocument :: Maybe ErrorDocument
$sel:errorDocument:WebsiteConfiguration' :: WebsiteConfiguration -> Maybe ErrorDocument
errorDocument} -> Maybe ErrorDocument
errorDocument) (\s :: WebsiteConfiguration
s@WebsiteConfiguration' {} Maybe ErrorDocument
a -> WebsiteConfiguration
s {$sel:errorDocument:WebsiteConfiguration' :: Maybe ErrorDocument
errorDocument = Maybe ErrorDocument
a} :: WebsiteConfiguration)

-- | The name of the index document for the website.
websiteConfiguration_indexDocument :: Lens.Lens' WebsiteConfiguration (Prelude.Maybe IndexDocument)
websiteConfiguration_indexDocument :: (Maybe IndexDocument -> f (Maybe IndexDocument))
-> WebsiteConfiguration -> f WebsiteConfiguration
websiteConfiguration_indexDocument = (WebsiteConfiguration -> Maybe IndexDocument)
-> (WebsiteConfiguration
    -> Maybe IndexDocument -> WebsiteConfiguration)
-> Lens
     WebsiteConfiguration
     WebsiteConfiguration
     (Maybe IndexDocument)
     (Maybe IndexDocument)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebsiteConfiguration' {Maybe IndexDocument
indexDocument :: Maybe IndexDocument
$sel:indexDocument:WebsiteConfiguration' :: WebsiteConfiguration -> Maybe IndexDocument
indexDocument} -> Maybe IndexDocument
indexDocument) (\s :: WebsiteConfiguration
s@WebsiteConfiguration' {} Maybe IndexDocument
a -> WebsiteConfiguration
s {$sel:indexDocument:WebsiteConfiguration' :: Maybe IndexDocument
indexDocument = Maybe IndexDocument
a} :: WebsiteConfiguration)

-- | Rules that define when a redirect is applied and the redirect behavior.
websiteConfiguration_routingRules :: Lens.Lens' WebsiteConfiguration (Prelude.Maybe [RoutingRule])
websiteConfiguration_routingRules :: (Maybe [RoutingRule] -> f (Maybe [RoutingRule]))
-> WebsiteConfiguration -> f WebsiteConfiguration
websiteConfiguration_routingRules = (WebsiteConfiguration -> Maybe [RoutingRule])
-> (WebsiteConfiguration
    -> Maybe [RoutingRule] -> WebsiteConfiguration)
-> Lens
     WebsiteConfiguration
     WebsiteConfiguration
     (Maybe [RoutingRule])
     (Maybe [RoutingRule])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebsiteConfiguration' {Maybe [RoutingRule]
routingRules :: Maybe [RoutingRule]
$sel:routingRules:WebsiteConfiguration' :: WebsiteConfiguration -> Maybe [RoutingRule]
routingRules} -> Maybe [RoutingRule]
routingRules) (\s :: WebsiteConfiguration
s@WebsiteConfiguration' {} Maybe [RoutingRule]
a -> WebsiteConfiguration
s {$sel:routingRules:WebsiteConfiguration' :: Maybe [RoutingRule]
routingRules = Maybe [RoutingRule]
a} :: WebsiteConfiguration) ((Maybe [RoutingRule] -> f (Maybe [RoutingRule]))
 -> WebsiteConfiguration -> f WebsiteConfiguration)
-> ((Maybe [RoutingRule] -> f (Maybe [RoutingRule]))
    -> Maybe [RoutingRule] -> f (Maybe [RoutingRule]))
-> (Maybe [RoutingRule] -> f (Maybe [RoutingRule]))
-> WebsiteConfiguration
-> f WebsiteConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [RoutingRule] [RoutingRule] [RoutingRule] [RoutingRule]
-> Iso
     (Maybe [RoutingRule])
     (Maybe [RoutingRule])
     (Maybe [RoutingRule])
     (Maybe [RoutingRule])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [RoutingRule] [RoutingRule] [RoutingRule] [RoutingRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.Hashable WebsiteConfiguration

instance Prelude.NFData WebsiteConfiguration

instance Core.ToXML WebsiteConfiguration where
  toXML :: WebsiteConfiguration -> XML
toXML WebsiteConfiguration' {Maybe [RoutingRule]
Maybe ErrorDocument
Maybe IndexDocument
Maybe RedirectAllRequestsTo
routingRules :: Maybe [RoutingRule]
indexDocument :: Maybe IndexDocument
errorDocument :: Maybe ErrorDocument
redirectAllRequestsTo :: Maybe RedirectAllRequestsTo
$sel:routingRules:WebsiteConfiguration' :: WebsiteConfiguration -> Maybe [RoutingRule]
$sel:indexDocument:WebsiteConfiguration' :: WebsiteConfiguration -> Maybe IndexDocument
$sel:errorDocument:WebsiteConfiguration' :: WebsiteConfiguration -> Maybe ErrorDocument
$sel:redirectAllRequestsTo:WebsiteConfiguration' :: WebsiteConfiguration -> Maybe RedirectAllRequestsTo
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"RedirectAllRequestsTo"
          Name -> Maybe RedirectAllRequestsTo -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe RedirectAllRequestsTo
redirectAllRequestsTo,
        Name
"ErrorDocument" Name -> Maybe ErrorDocument -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe ErrorDocument
errorDocument,
        Name
"IndexDocument" Name -> Maybe IndexDocument -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe IndexDocument
indexDocument,
        Name
"RoutingRules"
          Name -> XML -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe XML -> XML
forall a. ToXML a => a -> XML
Core.toXML
            ( Name -> [RoutingRule] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"RoutingRule"
                ([RoutingRule] -> XML) -> Maybe [RoutingRule] -> Maybe XML
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [RoutingRule]
routingRules
            )
      ]