{-# 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.Glue.Types.FilterValue
-- 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.Glue.Types.FilterValue where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Glue.Types.FilterValueType
import qualified Amazonka.Prelude as Prelude

-- | Represents a single entry in the list of values for a
-- @FilterExpression@.
--
-- /See:/ 'newFilterValue' smart constructor.
data FilterValue = FilterValue'
  { -- | The type of filter value.
    FilterValue -> FilterValueType
type' :: FilterValueType,
    -- | The value to be associated.
    FilterValue -> [Text]
value :: [Prelude.Text]
  }
  deriving (FilterValue -> FilterValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilterValue -> FilterValue -> Bool
$c/= :: FilterValue -> FilterValue -> Bool
== :: FilterValue -> FilterValue -> Bool
$c== :: FilterValue -> FilterValue -> Bool
Prelude.Eq, ReadPrec [FilterValue]
ReadPrec FilterValue
Int -> ReadS FilterValue
ReadS [FilterValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FilterValue]
$creadListPrec :: ReadPrec [FilterValue]
readPrec :: ReadPrec FilterValue
$creadPrec :: ReadPrec FilterValue
readList :: ReadS [FilterValue]
$creadList :: ReadS [FilterValue]
readsPrec :: Int -> ReadS FilterValue
$creadsPrec :: Int -> ReadS FilterValue
Prelude.Read, Int -> FilterValue -> ShowS
[FilterValue] -> ShowS
FilterValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FilterValue] -> ShowS
$cshowList :: [FilterValue] -> ShowS
show :: FilterValue -> String
$cshow :: FilterValue -> String
showsPrec :: Int -> FilterValue -> ShowS
$cshowsPrec :: Int -> FilterValue -> ShowS
Prelude.Show, forall x. Rep FilterValue x -> FilterValue
forall x. FilterValue -> Rep FilterValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FilterValue x -> FilterValue
$cfrom :: forall x. FilterValue -> Rep FilterValue x
Prelude.Generic)

-- |
-- Create a value of 'FilterValue' 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:
--
-- 'type'', 'filterValue_type' - The type of filter value.
--
-- 'value', 'filterValue_value' - The value to be associated.
newFilterValue ::
  -- | 'type''
  FilterValueType ->
  FilterValue
newFilterValue :: FilterValueType -> FilterValue
newFilterValue FilterValueType
pType_ =
  FilterValue'
    { $sel:type':FilterValue' :: FilterValueType
type' = FilterValueType
pType_,
      $sel:value:FilterValue' :: [Text]
value = forall a. Monoid a => a
Prelude.mempty
    }

-- | The type of filter value.
filterValue_type :: Lens.Lens' FilterValue FilterValueType
filterValue_type :: Lens' FilterValue FilterValueType
filterValue_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FilterValue' {FilterValueType
type' :: FilterValueType
$sel:type':FilterValue' :: FilterValue -> FilterValueType
type'} -> FilterValueType
type') (\s :: FilterValue
s@FilterValue' {} FilterValueType
a -> FilterValue
s {$sel:type':FilterValue' :: FilterValueType
type' = FilterValueType
a} :: FilterValue)

-- | The value to be associated.
filterValue_value :: Lens.Lens' FilterValue [Prelude.Text]
filterValue_value :: Lens' FilterValue [Text]
filterValue_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FilterValue' {[Text]
value :: [Text]
$sel:value:FilterValue' :: FilterValue -> [Text]
value} -> [Text]
value) (\s :: FilterValue
s@FilterValue' {} [Text]
a -> FilterValue
s {$sel:value:FilterValue' :: [Text]
value = [Text]
a} :: FilterValue) 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

instance Data.FromJSON FilterValue where
  parseJSON :: Value -> Parser FilterValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FilterValue"
      ( \Object
x ->
          FilterValueType -> [Text] -> FilterValue
FilterValue'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Type")
            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" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable FilterValue where
  hashWithSalt :: Int -> FilterValue -> Int
hashWithSalt Int
_salt FilterValue' {[Text]
FilterValueType
value :: [Text]
type' :: FilterValueType
$sel:value:FilterValue' :: FilterValue -> [Text]
$sel:type':FilterValue' :: FilterValue -> FilterValueType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FilterValueType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
value

instance Prelude.NFData FilterValue where
  rnf :: FilterValue -> ()
rnf FilterValue' {[Text]
FilterValueType
value :: [Text]
type' :: FilterValueType
$sel:value:FilterValue' :: FilterValue -> [Text]
$sel:type':FilterValue' :: FilterValue -> FilterValueType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf FilterValueType
type' seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
value

instance Data.ToJSON FilterValue where
  toJSON :: FilterValue -> Value
toJSON FilterValue' {[Text]
FilterValueType
value :: [Text]
type' :: FilterValueType
$sel:value:FilterValue' :: FilterValue -> [Text]
$sel:type':FilterValue' :: FilterValue -> FilterValueType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FilterValueType
type'),
            forall a. a -> Maybe a
Prelude.Just (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
value)
          ]
      )