{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.S3.Types.Condition where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 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,
    -- | 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
  }
  deriving (Condition -> Condition -> Bool
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]
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
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. 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:
--
-- '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.
--
-- '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>.
newCondition ::
  Condition
newCondition :: Condition
newCondition =
  Condition'
    { $sel:httpErrorCodeReturnedEquals:Condition' :: Maybe Text
httpErrorCodeReturnedEquals =
        forall a. Maybe a
Prelude.Nothing,
      $sel:keyPrefixEquals:Condition' :: Maybe Text
keyPrefixEquals = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' Condition (Maybe Text)
condition_httpErrorCodeReturnedEquals = 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)

-- | 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 :: Lens' Condition (Maybe Text)
condition_keyPrefixEquals = 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)

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

instance Prelude.Hashable Condition where
  hashWithSalt :: Int -> Condition -> Int
hashWithSalt Int
_salt Condition' {Maybe Text
keyPrefixEquals :: Maybe Text
httpErrorCodeReturnedEquals :: Maybe Text
$sel:keyPrefixEquals:Condition' :: Condition -> Maybe Text
$sel:httpErrorCodeReturnedEquals:Condition' :: Condition -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
httpErrorCodeReturnedEquals
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
keyPrefixEquals

instance Prelude.NFData Condition where
  rnf :: Condition -> ()
rnf Condition' {Maybe Text
keyPrefixEquals :: Maybe Text
httpErrorCodeReturnedEquals :: Maybe Text
$sel:keyPrefixEquals:Condition' :: Condition -> Maybe Text
$sel:httpErrorCodeReturnedEquals:Condition' :: Condition -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
httpErrorCodeReturnedEquals
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
keyPrefixEquals

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