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

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

-- | A container for describing a condition that must be met for the
-- specified redirect to apply. For example, 1. If request is for pages in
-- the @\/docs@ folder, redirect to the @\/documents@ folder. 2. If request
-- results in HTTP error 4xx, redirect request to another host where you
-- might process the error.
--
-- /See:/ 'newCondition' smart constructor.
data Condition = Condition'
  { -- | The object key name prefix when the redirect is applied. For example, to
    -- redirect requests for @ExamplePage.html@, the key prefix will be
    -- @ExamplePage.html@. To redirect request for all pages with the prefix
    -- @docs\/@, the key prefix will be @\/docs@, which identifies all objects
    -- in the @docs\/@ folder. Required when the parent element @Condition@ is
    -- specified and sibling @HttpErrorCodeReturnedEquals@ is not specified. If
    -- both conditions are specified, both must be true for the redirect to be
    -- applied.
    --
    -- Replacement must be made for object keys containing special characters
    -- (such as carriage returns) when using XML requests. For more
    -- information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
    Condition -> Maybe Text
keyPrefixEquals :: Prelude.Maybe Prelude.Text,
    -- | The HTTP error code when the redirect is applied. In the event of an
    -- error, if the error code equals this value, then the specified redirect
    -- is applied. Required when parent element @Condition@ is specified and
    -- sibling @KeyPrefixEquals@ is not specified. If both are specified, then
    -- both must be true for the redirect to be applied.
    Condition -> Maybe Text
httpErrorCodeReturnedEquals :: Prelude.Maybe Prelude.Text
  }
  deriving (Condition -> Condition -> Bool
(Condition -> Condition -> Bool)
-> (Condition -> Condition -> Bool) -> Eq Condition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Condition -> Condition -> Bool
$c/= :: Condition -> Condition -> Bool
== :: Condition -> Condition -> Bool
$c== :: Condition -> Condition -> Bool
Prelude.Eq, ReadPrec [Condition]
ReadPrec Condition
Int -> ReadS Condition
ReadS [Condition]
(Int -> ReadS Condition)
-> ReadS [Condition]
-> ReadPrec Condition
-> ReadPrec [Condition]
-> Read Condition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Condition]
$creadListPrec :: ReadPrec [Condition]
readPrec :: ReadPrec Condition
$creadPrec :: ReadPrec Condition
readList :: ReadS [Condition]
$creadList :: ReadS [Condition]
readsPrec :: Int -> ReadS Condition
$creadsPrec :: Int -> ReadS Condition
Prelude.Read, Int -> Condition -> ShowS
[Condition] -> ShowS
Condition -> String
(Int -> Condition -> ShowS)
-> (Condition -> String)
-> ([Condition] -> ShowS)
-> Show Condition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Condition] -> ShowS
$cshowList :: [Condition] -> ShowS
show :: Condition -> String
$cshow :: Condition -> String
showsPrec :: Int -> Condition -> ShowS
$cshowsPrec :: Int -> Condition -> ShowS
Prelude.Show, (forall x. Condition -> Rep Condition x)
-> (forall x. Rep Condition x -> Condition) -> Generic Condition
forall x. Rep Condition x -> Condition
forall x. Condition -> Rep Condition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Condition x -> Condition
$cfrom :: forall x. Condition -> Rep Condition x
Prelude.Generic)

-- |
-- Create a value of 'Condition' 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:
--
-- 'keyPrefixEquals', 'condition_keyPrefixEquals' - The object key name prefix when the redirect is applied. For example, to
-- redirect requests for @ExamplePage.html@, the key prefix will be
-- @ExamplePage.html@. To redirect request for all pages with the prefix
-- @docs\/@, the key prefix will be @\/docs@, which identifies all objects
-- in the @docs\/@ folder. Required when the parent element @Condition@ is
-- specified and sibling @HttpErrorCodeReturnedEquals@ is not specified. If
-- both conditions are specified, both must be true for the redirect to be
-- applied.
--
-- Replacement must be made for object keys containing special characters
-- (such as carriage returns) when using XML requests. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
--
-- 'httpErrorCodeReturnedEquals', 'condition_httpErrorCodeReturnedEquals' - The HTTP error code when the redirect is applied. In the event of an
-- error, if the error code equals this value, then the specified redirect
-- is applied. Required when parent element @Condition@ is specified and
-- sibling @KeyPrefixEquals@ is not specified. If both are specified, then
-- both must be true for the redirect to be applied.
newCondition ::
  Condition
newCondition :: Condition
newCondition =
  Condition' :: Maybe Text -> Maybe Text -> Condition
Condition'
    { $sel:keyPrefixEquals:Condition' :: Maybe Text
keyPrefixEquals = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpErrorCodeReturnedEquals:Condition' :: Maybe Text
httpErrorCodeReturnedEquals = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The object key name prefix when the redirect is applied. For example, to
-- redirect requests for @ExamplePage.html@, the key prefix will be
-- @ExamplePage.html@. To redirect request for all pages with the prefix
-- @docs\/@, the key prefix will be @\/docs@, which identifies all objects
-- in the @docs\/@ folder. Required when the parent element @Condition@ is
-- specified and sibling @HttpErrorCodeReturnedEquals@ is not specified. If
-- both conditions are specified, both must be true for the redirect to be
-- applied.
--
-- Replacement must be made for object keys containing special characters
-- (such as carriage returns) when using XML requests. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
condition_keyPrefixEquals :: Lens.Lens' Condition (Prelude.Maybe Prelude.Text)
condition_keyPrefixEquals :: (Maybe Text -> f (Maybe Text)) -> Condition -> f Condition
condition_keyPrefixEquals = (Condition -> Maybe Text)
-> (Condition -> Maybe Text -> Condition)
-> Lens Condition Condition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe Text
keyPrefixEquals :: Maybe Text
$sel:keyPrefixEquals:Condition' :: Condition -> Maybe Text
keyPrefixEquals} -> Maybe Text
keyPrefixEquals) (\s :: Condition
s@Condition' {} Maybe Text
a -> Condition
s {$sel:keyPrefixEquals:Condition' :: Maybe Text
keyPrefixEquals = Maybe Text
a} :: Condition)

-- | The HTTP error code when the redirect is applied. In the event of an
-- error, if the error code equals this value, then the specified redirect
-- is applied. Required when parent element @Condition@ is specified and
-- sibling @KeyPrefixEquals@ is not specified. If both are specified, then
-- both must be true for the redirect to be applied.
condition_httpErrorCodeReturnedEquals :: Lens.Lens' Condition (Prelude.Maybe Prelude.Text)
condition_httpErrorCodeReturnedEquals :: (Maybe Text -> f (Maybe Text)) -> Condition -> f Condition
condition_httpErrorCodeReturnedEquals = (Condition -> Maybe Text)
-> (Condition -> Maybe Text -> Condition)
-> Lens Condition Condition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe Text
httpErrorCodeReturnedEquals :: Maybe Text
$sel:httpErrorCodeReturnedEquals:Condition' :: Condition -> Maybe Text
httpErrorCodeReturnedEquals} -> Maybe Text
httpErrorCodeReturnedEquals) (\s :: Condition
s@Condition' {} Maybe Text
a -> Condition
s {$sel:httpErrorCodeReturnedEquals:Condition' :: Maybe Text
httpErrorCodeReturnedEquals = Maybe Text
a} :: Condition)

instance Core.FromXML Condition where
  parseXML :: [Node] -> Either String Condition
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Condition
Condition'
      (Maybe Text -> Maybe Text -> Condition)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Condition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"KeyPrefixEquals")
      Either String (Maybe Text -> Condition)
-> Either String (Maybe Text) -> Either String Condition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"HttpErrorCodeReturnedEquals")

instance Prelude.Hashable Condition

instance Prelude.NFData Condition

instance Core.ToXML Condition where
  toXML :: Condition -> XML
toXML Condition' {Maybe Text
httpErrorCodeReturnedEquals :: Maybe Text
keyPrefixEquals :: Maybe Text
$sel:httpErrorCodeReturnedEquals:Condition' :: Condition -> Maybe Text
$sel:keyPrefixEquals:Condition' :: Condition -> Maybe Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"KeyPrefixEquals" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
keyPrefixEquals,
        Name
"HttpErrorCodeReturnedEquals"
          Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
httpErrorCodeReturnedEquals
      ]