{-# 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.LakeFormation.Types.RowFilter
-- 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.LakeFormation.Types.RowFilter where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LakeFormation.Types.AllRowsWildcard
import qualified Amazonka.Prelude as Prelude

-- | A PartiQL predicate.
--
-- /See:/ 'newRowFilter' smart constructor.
data RowFilter = RowFilter'
  { -- | A wildcard for all rows.
    RowFilter -> Maybe AllRowsWildcard
allRowsWildcard :: Prelude.Maybe AllRowsWildcard,
    -- | A filter expression.
    RowFilter -> Maybe Text
filterExpression :: Prelude.Maybe Prelude.Text
  }
  deriving (RowFilter -> RowFilter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RowFilter -> RowFilter -> Bool
$c/= :: RowFilter -> RowFilter -> Bool
== :: RowFilter -> RowFilter -> Bool
$c== :: RowFilter -> RowFilter -> Bool
Prelude.Eq, ReadPrec [RowFilter]
ReadPrec RowFilter
Int -> ReadS RowFilter
ReadS [RowFilter]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RowFilter]
$creadListPrec :: ReadPrec [RowFilter]
readPrec :: ReadPrec RowFilter
$creadPrec :: ReadPrec RowFilter
readList :: ReadS [RowFilter]
$creadList :: ReadS [RowFilter]
readsPrec :: Int -> ReadS RowFilter
$creadsPrec :: Int -> ReadS RowFilter
Prelude.Read, Int -> RowFilter -> ShowS
[RowFilter] -> ShowS
RowFilter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RowFilter] -> ShowS
$cshowList :: [RowFilter] -> ShowS
show :: RowFilter -> String
$cshow :: RowFilter -> String
showsPrec :: Int -> RowFilter -> ShowS
$cshowsPrec :: Int -> RowFilter -> ShowS
Prelude.Show, forall x. Rep RowFilter x -> RowFilter
forall x. RowFilter -> Rep RowFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RowFilter x -> RowFilter
$cfrom :: forall x. RowFilter -> Rep RowFilter x
Prelude.Generic)

-- |
-- Create a value of 'RowFilter' 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:
--
-- 'allRowsWildcard', 'rowFilter_allRowsWildcard' - A wildcard for all rows.
--
-- 'filterExpression', 'rowFilter_filterExpression' - A filter expression.
newRowFilter ::
  RowFilter
newRowFilter :: RowFilter
newRowFilter =
  RowFilter'
    { $sel:allRowsWildcard:RowFilter' :: Maybe AllRowsWildcard
allRowsWildcard = forall a. Maybe a
Prelude.Nothing,
      $sel:filterExpression:RowFilter' :: Maybe Text
filterExpression = forall a. Maybe a
Prelude.Nothing
    }

-- | A wildcard for all rows.
rowFilter_allRowsWildcard :: Lens.Lens' RowFilter (Prelude.Maybe AllRowsWildcard)
rowFilter_allRowsWildcard :: Lens' RowFilter (Maybe AllRowsWildcard)
rowFilter_allRowsWildcard = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RowFilter' {Maybe AllRowsWildcard
allRowsWildcard :: Maybe AllRowsWildcard
$sel:allRowsWildcard:RowFilter' :: RowFilter -> Maybe AllRowsWildcard
allRowsWildcard} -> Maybe AllRowsWildcard
allRowsWildcard) (\s :: RowFilter
s@RowFilter' {} Maybe AllRowsWildcard
a -> RowFilter
s {$sel:allRowsWildcard:RowFilter' :: Maybe AllRowsWildcard
allRowsWildcard = Maybe AllRowsWildcard
a} :: RowFilter)

-- | A filter expression.
rowFilter_filterExpression :: Lens.Lens' RowFilter (Prelude.Maybe Prelude.Text)
rowFilter_filterExpression :: Lens' RowFilter (Maybe Text)
rowFilter_filterExpression = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RowFilter' {Maybe Text
filterExpression :: Maybe Text
$sel:filterExpression:RowFilter' :: RowFilter -> Maybe Text
filterExpression} -> Maybe Text
filterExpression) (\s :: RowFilter
s@RowFilter' {} Maybe Text
a -> RowFilter
s {$sel:filterExpression:RowFilter' :: Maybe Text
filterExpression = Maybe Text
a} :: RowFilter)

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

instance Prelude.Hashable RowFilter where
  hashWithSalt :: Int -> RowFilter -> Int
hashWithSalt Int
_salt RowFilter' {Maybe Text
Maybe AllRowsWildcard
filterExpression :: Maybe Text
allRowsWildcard :: Maybe AllRowsWildcard
$sel:filterExpression:RowFilter' :: RowFilter -> Maybe Text
$sel:allRowsWildcard:RowFilter' :: RowFilter -> Maybe AllRowsWildcard
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AllRowsWildcard
allRowsWildcard
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
filterExpression

instance Prelude.NFData RowFilter where
  rnf :: RowFilter -> ()
rnf RowFilter' {Maybe Text
Maybe AllRowsWildcard
filterExpression :: Maybe Text
allRowsWildcard :: Maybe AllRowsWildcard
$sel:filterExpression:RowFilter' :: RowFilter -> Maybe Text
$sel:allRowsWildcard:RowFilter' :: RowFilter -> Maybe AllRowsWildcard
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe AllRowsWildcard
allRowsWildcard
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
filterExpression

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