{-# 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.Amplify.Types.CustomRule
-- 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.Amplify.Types.CustomRule 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

-- | Describes a custom rewrite or redirect rule.
--
-- /See:/ 'newCustomRule' smart constructor.
data CustomRule = CustomRule'
  { -- | The condition for a URL rewrite or redirect rule, such as a country
    -- code.
    CustomRule -> Maybe Text
condition :: Prelude.Maybe Prelude.Text,
    -- | The status code for a URL rewrite or redirect rule.
    --
    -- [200]
    --     Represents a 200 rewrite rule.
    --
    -- [301]
    --     Represents a 301 (moved pemanently) redirect rule. This and all
    --     future requests should be directed to the target URL.
    --
    -- [302]
    --     Represents a 302 temporary redirect rule.
    --
    -- [404]
    --     Represents a 404 redirect rule.
    --
    -- [404-200]
    --     Represents a 404 rewrite rule.
    CustomRule -> Maybe Text
status :: Prelude.Maybe Prelude.Text,
    -- | The source pattern for a URL rewrite or redirect rule.
    CustomRule -> Text
source :: Prelude.Text,
    -- | The target pattern for a URL rewrite or redirect rule.
    CustomRule -> Text
target :: Prelude.Text
  }
  deriving (CustomRule -> CustomRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomRule -> CustomRule -> Bool
$c/= :: CustomRule -> CustomRule -> Bool
== :: CustomRule -> CustomRule -> Bool
$c== :: CustomRule -> CustomRule -> Bool
Prelude.Eq, ReadPrec [CustomRule]
ReadPrec CustomRule
Int -> ReadS CustomRule
ReadS [CustomRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomRule]
$creadListPrec :: ReadPrec [CustomRule]
readPrec :: ReadPrec CustomRule
$creadPrec :: ReadPrec CustomRule
readList :: ReadS [CustomRule]
$creadList :: ReadS [CustomRule]
readsPrec :: Int -> ReadS CustomRule
$creadsPrec :: Int -> ReadS CustomRule
Prelude.Read, Int -> CustomRule -> ShowS
[CustomRule] -> ShowS
CustomRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomRule] -> ShowS
$cshowList :: [CustomRule] -> ShowS
show :: CustomRule -> String
$cshow :: CustomRule -> String
showsPrec :: Int -> CustomRule -> ShowS
$cshowsPrec :: Int -> CustomRule -> ShowS
Prelude.Show, forall x. Rep CustomRule x -> CustomRule
forall x. CustomRule -> Rep CustomRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomRule x -> CustomRule
$cfrom :: forall x. CustomRule -> Rep CustomRule x
Prelude.Generic)

-- |
-- Create a value of 'CustomRule' 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:
--
-- 'condition', 'customRule_condition' - The condition for a URL rewrite or redirect rule, such as a country
-- code.
--
-- 'status', 'customRule_status' - The status code for a URL rewrite or redirect rule.
--
-- [200]
--     Represents a 200 rewrite rule.
--
-- [301]
--     Represents a 301 (moved pemanently) redirect rule. This and all
--     future requests should be directed to the target URL.
--
-- [302]
--     Represents a 302 temporary redirect rule.
--
-- [404]
--     Represents a 404 redirect rule.
--
-- [404-200]
--     Represents a 404 rewrite rule.
--
-- 'source', 'customRule_source' - The source pattern for a URL rewrite or redirect rule.
--
-- 'target', 'customRule_target' - The target pattern for a URL rewrite or redirect rule.
newCustomRule ::
  -- | 'source'
  Prelude.Text ->
  -- | 'target'
  Prelude.Text ->
  CustomRule
newCustomRule :: Text -> Text -> CustomRule
newCustomRule Text
pSource_ Text
pTarget_ =
  CustomRule'
    { $sel:condition:CustomRule' :: Maybe Text
condition = forall a. Maybe a
Prelude.Nothing,
      $sel:status:CustomRule' :: Maybe Text
status = forall a. Maybe a
Prelude.Nothing,
      $sel:source:CustomRule' :: Text
source = Text
pSource_,
      $sel:target:CustomRule' :: Text
target = Text
pTarget_
    }

-- | The condition for a URL rewrite or redirect rule, such as a country
-- code.
customRule_condition :: Lens.Lens' CustomRule (Prelude.Maybe Prelude.Text)
customRule_condition :: Lens' CustomRule (Maybe Text)
customRule_condition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomRule' {Maybe Text
condition :: Maybe Text
$sel:condition:CustomRule' :: CustomRule -> Maybe Text
condition} -> Maybe Text
condition) (\s :: CustomRule
s@CustomRule' {} Maybe Text
a -> CustomRule
s {$sel:condition:CustomRule' :: Maybe Text
condition = Maybe Text
a} :: CustomRule)

-- | The status code for a URL rewrite or redirect rule.
--
-- [200]
--     Represents a 200 rewrite rule.
--
-- [301]
--     Represents a 301 (moved pemanently) redirect rule. This and all
--     future requests should be directed to the target URL.
--
-- [302]
--     Represents a 302 temporary redirect rule.
--
-- [404]
--     Represents a 404 redirect rule.
--
-- [404-200]
--     Represents a 404 rewrite rule.
customRule_status :: Lens.Lens' CustomRule (Prelude.Maybe Prelude.Text)
customRule_status :: Lens' CustomRule (Maybe Text)
customRule_status = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomRule' {Maybe Text
status :: Maybe Text
$sel:status:CustomRule' :: CustomRule -> Maybe Text
status} -> Maybe Text
status) (\s :: CustomRule
s@CustomRule' {} Maybe Text
a -> CustomRule
s {$sel:status:CustomRule' :: Maybe Text
status = Maybe Text
a} :: CustomRule)

-- | The source pattern for a URL rewrite or redirect rule.
customRule_source :: Lens.Lens' CustomRule Prelude.Text
customRule_source :: Lens' CustomRule Text
customRule_source = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomRule' {Text
source :: Text
$sel:source:CustomRule' :: CustomRule -> Text
source} -> Text
source) (\s :: CustomRule
s@CustomRule' {} Text
a -> CustomRule
s {$sel:source:CustomRule' :: Text
source = Text
a} :: CustomRule)

-- | The target pattern for a URL rewrite or redirect rule.
customRule_target :: Lens.Lens' CustomRule Prelude.Text
customRule_target :: Lens' CustomRule Text
customRule_target = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomRule' {Text
target :: Text
$sel:target:CustomRule' :: CustomRule -> Text
target} -> Text
target) (\s :: CustomRule
s@CustomRule' {} Text
a -> CustomRule
s {$sel:target:CustomRule' :: Text
target = Text
a} :: CustomRule)

instance Data.FromJSON CustomRule where
  parseJSON :: Value -> Parser CustomRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CustomRule"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Text -> Text -> CustomRule
CustomRule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"condition")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"status")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"source")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"target")
      )

instance Prelude.Hashable CustomRule where
  hashWithSalt :: Int -> CustomRule -> Int
hashWithSalt Int
_salt CustomRule' {Maybe Text
Text
target :: Text
source :: Text
status :: Maybe Text
condition :: Maybe Text
$sel:target:CustomRule' :: CustomRule -> Text
$sel:source:CustomRule' :: CustomRule -> Text
$sel:status:CustomRule' :: CustomRule -> Maybe Text
$sel:condition:CustomRule' :: CustomRule -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
condition
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
status
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
source
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
target

instance Prelude.NFData CustomRule where
  rnf :: CustomRule -> ()
rnf CustomRule' {Maybe Text
Text
target :: Text
source :: Text
status :: Maybe Text
condition :: Maybe Text
$sel:target:CustomRule' :: CustomRule -> Text
$sel:source:CustomRule' :: CustomRule -> Text
$sel:status:CustomRule' :: CustomRule -> Maybe Text
$sel:condition:CustomRule' :: CustomRule -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
condition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
status
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
source
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
target

instance Data.ToJSON CustomRule where
  toJSON :: CustomRule -> Value
toJSON CustomRule' {Maybe Text
Text
target :: Text
source :: Text
status :: Maybe Text
condition :: Maybe Text
$sel:target:CustomRule' :: CustomRule -> Text
$sel:source:CustomRule' :: CustomRule -> Text
$sel:status:CustomRule' :: CustomRule -> Maybe Text
$sel:condition:CustomRule' :: CustomRule -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"condition" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
condition,
            (Key
"status" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
status,
            forall a. a -> Maybe a
Prelude.Just (Key
"source" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
source),
            forall a. a -> Maybe a
Prelude.Just (Key
"target" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
target)
          ]
      )