{-# 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.DataSync.Types.FilterRule
-- 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.DataSync.Types.FilterRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DataSync.Types.FilterType
import qualified Amazonka.Prelude as Prelude

-- | Specifies which files, folders, and objects to include or exclude when
-- transferring files from source to destination.
--
-- /See:/ 'newFilterRule' smart constructor.
data FilterRule = FilterRule'
  { -- | The type of filter rule to apply. DataSync only supports the
    -- SIMPLE_PATTERN rule type.
    FilterRule -> Maybe FilterType
filterType :: Prelude.Maybe FilterType,
    -- | A single filter string that consists of the patterns to include or
    -- exclude. The patterns are delimited by \"|\" (that is, a pipe), for
    -- example: @\/folder1|\/folder2@
    FilterRule -> Maybe Text
value :: Prelude.Maybe Prelude.Text
  }
  deriving (FilterRule -> FilterRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilterRule -> FilterRule -> Bool
$c/= :: FilterRule -> FilterRule -> Bool
== :: FilterRule -> FilterRule -> Bool
$c== :: FilterRule -> FilterRule -> Bool
Prelude.Eq, ReadPrec [FilterRule]
ReadPrec FilterRule
Int -> ReadS FilterRule
ReadS [FilterRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FilterRule]
$creadListPrec :: ReadPrec [FilterRule]
readPrec :: ReadPrec FilterRule
$creadPrec :: ReadPrec FilterRule
readList :: ReadS [FilterRule]
$creadList :: ReadS [FilterRule]
readsPrec :: Int -> ReadS FilterRule
$creadsPrec :: Int -> ReadS FilterRule
Prelude.Read, Int -> FilterRule -> ShowS
[FilterRule] -> ShowS
FilterRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FilterRule] -> ShowS
$cshowList :: [FilterRule] -> ShowS
show :: FilterRule -> String
$cshow :: FilterRule -> String
showsPrec :: Int -> FilterRule -> ShowS
$cshowsPrec :: Int -> FilterRule -> ShowS
Prelude.Show, forall x. Rep FilterRule x -> FilterRule
forall x. FilterRule -> Rep FilterRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FilterRule x -> FilterRule
$cfrom :: forall x. FilterRule -> Rep FilterRule x
Prelude.Generic)

-- |
-- Create a value of 'FilterRule' 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:
--
-- 'filterType', 'filterRule_filterType' - The type of filter rule to apply. DataSync only supports the
-- SIMPLE_PATTERN rule type.
--
-- 'value', 'filterRule_value' - A single filter string that consists of the patterns to include or
-- exclude. The patterns are delimited by \"|\" (that is, a pipe), for
-- example: @\/folder1|\/folder2@
newFilterRule ::
  FilterRule
newFilterRule :: FilterRule
newFilterRule =
  FilterRule'
    { $sel:filterType:FilterRule' :: Maybe FilterType
filterType = forall a. Maybe a
Prelude.Nothing,
      $sel:value:FilterRule' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing
    }

-- | The type of filter rule to apply. DataSync only supports the
-- SIMPLE_PATTERN rule type.
filterRule_filterType :: Lens.Lens' FilterRule (Prelude.Maybe FilterType)
filterRule_filterType :: Lens' FilterRule (Maybe FilterType)
filterRule_filterType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FilterRule' {Maybe FilterType
filterType :: Maybe FilterType
$sel:filterType:FilterRule' :: FilterRule -> Maybe FilterType
filterType} -> Maybe FilterType
filterType) (\s :: FilterRule
s@FilterRule' {} Maybe FilterType
a -> FilterRule
s {$sel:filterType:FilterRule' :: Maybe FilterType
filterType = Maybe FilterType
a} :: FilterRule)

-- | A single filter string that consists of the patterns to include or
-- exclude. The patterns are delimited by \"|\" (that is, a pipe), for
-- example: @\/folder1|\/folder2@
filterRule_value :: Lens.Lens' FilterRule (Prelude.Maybe Prelude.Text)
filterRule_value :: Lens' FilterRule (Maybe Text)
filterRule_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FilterRule' {Maybe Text
value :: Maybe Text
$sel:value:FilterRule' :: FilterRule -> Maybe Text
value} -> Maybe Text
value) (\s :: FilterRule
s@FilterRule' {} Maybe Text
a -> FilterRule
s {$sel:value:FilterRule' :: Maybe Text
value = Maybe Text
a} :: FilterRule)

instance Data.FromJSON FilterRule where
  parseJSON :: Value -> Parser FilterRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FilterRule"
      ( \Object
x ->
          Maybe FilterType -> Maybe Text -> FilterRule
FilterRule'
            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
"FilterType")
            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
"Value")
      )

instance Prelude.Hashable FilterRule where
  hashWithSalt :: Int -> FilterRule -> Int
hashWithSalt Int
_salt FilterRule' {Maybe Text
Maybe FilterType
value :: Maybe Text
filterType :: Maybe FilterType
$sel:value:FilterRule' :: FilterRule -> Maybe Text
$sel:filterType:FilterRule' :: FilterRule -> Maybe FilterType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe FilterType
filterType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value

instance Prelude.NFData FilterRule where
  rnf :: FilterRule -> ()
rnf FilterRule' {Maybe Text
Maybe FilterType
value :: Maybe Text
filterType :: Maybe FilterType
$sel:value:FilterRule' :: FilterRule -> Maybe Text
$sel:filterType:FilterRule' :: FilterRule -> Maybe FilterType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe FilterType
filterType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value

instance Data.ToJSON FilterRule where
  toJSON :: FilterRule -> Value
toJSON FilterRule' {Maybe Text
Maybe FilterType
value :: Maybe Text
filterType :: Maybe FilterType
$sel:value:FilterRule' :: FilterRule -> Maybe Text
$sel:filterType:FilterRule' :: FilterRule -> Maybe FilterType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"FilterType" 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 FilterType
filterType,
            (Key
"Value" 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
value
          ]
      )