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

import qualified Amazonka.Core as Core
import Amazonka.DataSync.Types.LocationFilterName
import Amazonka.DataSync.Types.Operator
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | You can use API filters to narrow down the list of resources returned by
-- @ListLocations@. For example, to retrieve all your Amazon S3 locations,
-- you can use @ListLocations@ with filter name @LocationType S3@ and
-- @Operator Equals@.
--
-- /See:/ 'newLocationFilter' smart constructor.
data LocationFilter = LocationFilter'
  { -- | The name of the filter being used. Each API call supports a list of
    -- filters that are available for it (for example, @LocationType@ for
    -- @ListLocations@).
    LocationFilter -> LocationFilterName
name :: LocationFilterName,
    -- | The values that you want to filter for. For example, you might want to
    -- display only Amazon S3 locations.
    LocationFilter -> [Text]
values :: [Prelude.Text],
    -- | The operator that is used to compare filter values (for example,
    -- @Equals@ or @Contains@). For more about API filtering operators, see
    -- <https://docs.aws.amazon.com/datasync/latest/userguide/query-resources.html API filters for ListTasks and ListLocations>.
    LocationFilter -> Operator
operator :: Operator
  }
  deriving (LocationFilter -> LocationFilter -> Bool
(LocationFilter -> LocationFilter -> Bool)
-> (LocationFilter -> LocationFilter -> Bool) -> Eq LocationFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LocationFilter -> LocationFilter -> Bool
$c/= :: LocationFilter -> LocationFilter -> Bool
== :: LocationFilter -> LocationFilter -> Bool
$c== :: LocationFilter -> LocationFilter -> Bool
Prelude.Eq, ReadPrec [LocationFilter]
ReadPrec LocationFilter
Int -> ReadS LocationFilter
ReadS [LocationFilter]
(Int -> ReadS LocationFilter)
-> ReadS [LocationFilter]
-> ReadPrec LocationFilter
-> ReadPrec [LocationFilter]
-> Read LocationFilter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LocationFilter]
$creadListPrec :: ReadPrec [LocationFilter]
readPrec :: ReadPrec LocationFilter
$creadPrec :: ReadPrec LocationFilter
readList :: ReadS [LocationFilter]
$creadList :: ReadS [LocationFilter]
readsPrec :: Int -> ReadS LocationFilter
$creadsPrec :: Int -> ReadS LocationFilter
Prelude.Read, Int -> LocationFilter -> ShowS
[LocationFilter] -> ShowS
LocationFilter -> String
(Int -> LocationFilter -> ShowS)
-> (LocationFilter -> String)
-> ([LocationFilter] -> ShowS)
-> Show LocationFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LocationFilter] -> ShowS
$cshowList :: [LocationFilter] -> ShowS
show :: LocationFilter -> String
$cshow :: LocationFilter -> String
showsPrec :: Int -> LocationFilter -> ShowS
$cshowsPrec :: Int -> LocationFilter -> ShowS
Prelude.Show, (forall x. LocationFilter -> Rep LocationFilter x)
-> (forall x. Rep LocationFilter x -> LocationFilter)
-> Generic LocationFilter
forall x. Rep LocationFilter x -> LocationFilter
forall x. LocationFilter -> Rep LocationFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LocationFilter x -> LocationFilter
$cfrom :: forall x. LocationFilter -> Rep LocationFilter x
Prelude.Generic)

-- |
-- Create a value of 'LocationFilter' 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:
--
-- 'name', 'locationFilter_name' - The name of the filter being used. Each API call supports a list of
-- filters that are available for it (for example, @LocationType@ for
-- @ListLocations@).
--
-- 'values', 'locationFilter_values' - The values that you want to filter for. For example, you might want to
-- display only Amazon S3 locations.
--
-- 'operator', 'locationFilter_operator' - The operator that is used to compare filter values (for example,
-- @Equals@ or @Contains@). For more about API filtering operators, see
-- <https://docs.aws.amazon.com/datasync/latest/userguide/query-resources.html API filters for ListTasks and ListLocations>.
newLocationFilter ::
  -- | 'name'
  LocationFilterName ->
  -- | 'operator'
  Operator ->
  LocationFilter
newLocationFilter :: LocationFilterName -> Operator -> LocationFilter
newLocationFilter LocationFilterName
pName_ Operator
pOperator_ =
  LocationFilter' :: LocationFilterName -> [Text] -> Operator -> LocationFilter
LocationFilter'
    { $sel:name:LocationFilter' :: LocationFilterName
name = LocationFilterName
pName_,
      $sel:values:LocationFilter' :: [Text]
values = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:operator:LocationFilter' :: Operator
operator = Operator
pOperator_
    }

-- | The name of the filter being used. Each API call supports a list of
-- filters that are available for it (for example, @LocationType@ for
-- @ListLocations@).
locationFilter_name :: Lens.Lens' LocationFilter LocationFilterName
locationFilter_name :: (LocationFilterName -> f LocationFilterName)
-> LocationFilter -> f LocationFilter
locationFilter_name = (LocationFilter -> LocationFilterName)
-> (LocationFilter -> LocationFilterName -> LocationFilter)
-> Lens
     LocationFilter LocationFilter LocationFilterName LocationFilterName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocationFilter' {LocationFilterName
name :: LocationFilterName
$sel:name:LocationFilter' :: LocationFilter -> LocationFilterName
name} -> LocationFilterName
name) (\s :: LocationFilter
s@LocationFilter' {} LocationFilterName
a -> LocationFilter
s {$sel:name:LocationFilter' :: LocationFilterName
name = LocationFilterName
a} :: LocationFilter)

-- | The values that you want to filter for. For example, you might want to
-- display only Amazon S3 locations.
locationFilter_values :: Lens.Lens' LocationFilter [Prelude.Text]
locationFilter_values :: ([Text] -> f [Text]) -> LocationFilter -> f LocationFilter
locationFilter_values = (LocationFilter -> [Text])
-> (LocationFilter -> [Text] -> LocationFilter)
-> Lens LocationFilter LocationFilter [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocationFilter' {[Text]
values :: [Text]
$sel:values:LocationFilter' :: LocationFilter -> [Text]
values} -> [Text]
values) (\s :: LocationFilter
s@LocationFilter' {} [Text]
a -> LocationFilter
s {$sel:values:LocationFilter' :: [Text]
values = [Text]
a} :: LocationFilter) (([Text] -> f [Text]) -> LocationFilter -> f LocationFilter)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> LocationFilter
-> f LocationFilter
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The operator that is used to compare filter values (for example,
-- @Equals@ or @Contains@). For more about API filtering operators, see
-- <https://docs.aws.amazon.com/datasync/latest/userguide/query-resources.html API filters for ListTasks and ListLocations>.
locationFilter_operator :: Lens.Lens' LocationFilter Operator
locationFilter_operator :: (Operator -> f Operator) -> LocationFilter -> f LocationFilter
locationFilter_operator = (LocationFilter -> Operator)
-> (LocationFilter -> Operator -> LocationFilter)
-> Lens LocationFilter LocationFilter Operator Operator
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocationFilter' {Operator
operator :: Operator
$sel:operator:LocationFilter' :: LocationFilter -> Operator
operator} -> Operator
operator) (\s :: LocationFilter
s@LocationFilter' {} Operator
a -> LocationFilter
s {$sel:operator:LocationFilter' :: Operator
operator = Operator
a} :: LocationFilter)

instance Prelude.Hashable LocationFilter

instance Prelude.NFData LocationFilter

instance Core.ToJSON LocationFilter where
  toJSON :: LocationFilter -> Value
toJSON LocationFilter' {[Text]
LocationFilterName
Operator
operator :: Operator
values :: [Text]
name :: LocationFilterName
$sel:operator:LocationFilter' :: LocationFilter -> Operator
$sel:values:LocationFilter' :: LocationFilter -> [Text]
$sel:name:LocationFilter' :: LocationFilter -> LocationFilterName
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> LocationFilterName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= LocationFilterName
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Values" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
values),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Operator" Text -> Operator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Operator
operator)
          ]
      )