{-# 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-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.LocationFilter 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.LocationFilterName
import Amazonka.DataSync.Types.Operator
import qualified Amazonka.Prelude as Prelude

-- | Narrow down the list of resources returned by @ListLocations@. For
-- example, to see all your Amazon S3 locations, create a filter using
-- @\"Name\": \"LocationType\"@, @\"Operator\": \"Equals\"@, and
-- @\"Values\": \"S3\"@.
--
-- For more information, see
-- <https://docs.aws.amazon.com/datasync/latest/userguide/query-resources.html filtering resources>.
--
-- /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@).
    LocationFilter -> Operator
operator :: Operator
  }
  deriving (LocationFilter -> LocationFilter -> Bool
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]
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
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. 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@).
newLocationFilter ::
  -- | 'name'
  LocationFilterName ->
  -- | 'operator'
  Operator ->
  LocationFilter
newLocationFilter :: LocationFilterName -> Operator -> LocationFilter
newLocationFilter LocationFilterName
pName_ Operator
pOperator_ =
  LocationFilter'
    { $sel:name:LocationFilter' :: LocationFilterName
name = LocationFilterName
pName_,
      $sel:values:LocationFilter' :: [Text]
values = 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 :: Lens' LocationFilter LocationFilterName
locationFilter_name = 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 :: Lens' LocationFilter [Text]
locationFilter_values = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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@).
locationFilter_operator :: Lens.Lens' LocationFilter Operator
locationFilter_operator :: Lens' LocationFilter Operator
locationFilter_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 where
  hashWithSalt :: Int -> LocationFilter -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` LocationFilterName
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
values
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Operator
operator

instance Prelude.NFData LocationFilter where
  rnf :: LocationFilter -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf LocationFilterName
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
values
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Operator
operator

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= LocationFilterName
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Values" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
values),
            forall a. a -> Maybe a
Prelude.Just (Key
"Operator" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Operator
operator)
          ]
      )