{-# 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.HoneyCode.Types.Filter
-- 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.HoneyCode.Types.Filter 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

-- | An object that represents a filter formula along with the id of the
-- context row under which the filter function needs to evaluate.
--
-- /See:/ 'newFilter' smart constructor.
data Filter = Filter'
  { -- | The optional contextRowId attribute can be used to specify the row id of
    -- the context row if the filter formula contains unqualified references to
    -- table columns and needs a context row to evaluate them successfully.
    Filter -> Maybe Text
contextRowId :: Prelude.Maybe Prelude.Text,
    -- | A formula representing a filter function that returns zero or more
    -- matching rows from a table. Valid formulas in this field return a list
    -- of rows from a table. The most common ways of writing a formula to
    -- return a list of rows are to use the FindRow() or Filter() functions.
    -- Any other formula that returns zero or more rows is also acceptable. For
    -- example, you can use a formula that points to a cell that contains a
    -- filter function.
    Filter -> Sensitive Text
formula :: Data.Sensitive Prelude.Text
  }
  deriving (Filter -> Filter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Filter -> Filter -> Bool
$c/= :: Filter -> Filter -> Bool
== :: Filter -> Filter -> Bool
$c== :: Filter -> Filter -> Bool
Prelude.Eq, Int -> Filter -> ShowS
[Filter] -> ShowS
Filter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Filter] -> ShowS
$cshowList :: [Filter] -> ShowS
show :: Filter -> String
$cshow :: Filter -> String
showsPrec :: Int -> Filter -> ShowS
$cshowsPrec :: Int -> Filter -> ShowS
Prelude.Show, forall x. Rep Filter x -> Filter
forall x. Filter -> Rep Filter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Filter x -> Filter
$cfrom :: forall x. Filter -> Rep Filter x
Prelude.Generic)

-- |
-- Create a value of 'Filter' 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:
--
-- 'contextRowId', 'filter_contextRowId' - The optional contextRowId attribute can be used to specify the row id of
-- the context row if the filter formula contains unqualified references to
-- table columns and needs a context row to evaluate them successfully.
--
-- 'formula', 'filter_formula' - A formula representing a filter function that returns zero or more
-- matching rows from a table. Valid formulas in this field return a list
-- of rows from a table. The most common ways of writing a formula to
-- return a list of rows are to use the FindRow() or Filter() functions.
-- Any other formula that returns zero or more rows is also acceptable. For
-- example, you can use a formula that points to a cell that contains a
-- filter function.
newFilter ::
  -- | 'formula'
  Prelude.Text ->
  Filter
newFilter :: Text -> Filter
newFilter Text
pFormula_ =
  Filter'
    { $sel:contextRowId:Filter' :: Maybe Text
contextRowId = forall a. Maybe a
Prelude.Nothing,
      $sel:formula:Filter' :: Sensitive Text
formula = forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pFormula_
    }

-- | The optional contextRowId attribute can be used to specify the row id of
-- the context row if the filter formula contains unqualified references to
-- table columns and needs a context row to evaluate them successfully.
filter_contextRowId :: Lens.Lens' Filter (Prelude.Maybe Prelude.Text)
filter_contextRowId :: Lens' Filter (Maybe Text)
filter_contextRowId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {Maybe Text
contextRowId :: Maybe Text
$sel:contextRowId:Filter' :: Filter -> Maybe Text
contextRowId} -> Maybe Text
contextRowId) (\s :: Filter
s@Filter' {} Maybe Text
a -> Filter
s {$sel:contextRowId:Filter' :: Maybe Text
contextRowId = Maybe Text
a} :: Filter)

-- | A formula representing a filter function that returns zero or more
-- matching rows from a table. Valid formulas in this field return a list
-- of rows from a table. The most common ways of writing a formula to
-- return a list of rows are to use the FindRow() or Filter() functions.
-- Any other formula that returns zero or more rows is also acceptable. For
-- example, you can use a formula that points to a cell that contains a
-- filter function.
filter_formula :: Lens.Lens' Filter Prelude.Text
filter_formula :: Lens' Filter Text
filter_formula = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {Sensitive Text
formula :: Sensitive Text
$sel:formula:Filter' :: Filter -> Sensitive Text
formula} -> Sensitive Text
formula) (\s :: Filter
s@Filter' {} Sensitive Text
a -> Filter
s {$sel:formula:Filter' :: Sensitive Text
formula = Sensitive Text
a} :: Filter) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Prelude.Hashable Filter where
  hashWithSalt :: Int -> Filter -> Int
hashWithSalt Int
_salt Filter' {Maybe Text
Sensitive Text
formula :: Sensitive Text
contextRowId :: Maybe Text
$sel:formula:Filter' :: Filter -> Sensitive Text
$sel:contextRowId:Filter' :: Filter -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
contextRowId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
formula

instance Prelude.NFData Filter where
  rnf :: Filter -> ()
rnf Filter' {Maybe Text
Sensitive Text
formula :: Sensitive Text
contextRowId :: Maybe Text
$sel:formula:Filter' :: Filter -> Sensitive Text
$sel:contextRowId:Filter' :: Filter -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
contextRowId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
formula

instance Data.ToJSON Filter where
  toJSON :: Filter -> Value
toJSON Filter' {Maybe Text
Sensitive Text
formula :: Sensitive Text
contextRowId :: Maybe Text
$sel:formula:Filter' :: Filter -> Sensitive Text
$sel:contextRowId:Filter' :: Filter -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"contextRowId" 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
contextRowId,
            forall a. a -> Maybe a
Prelude.Just (Key
"formula" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
formula)
          ]
      )