{-# 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.MechanicalTurk.Types.PolicyParameter
-- 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.MechanicalTurk.Types.PolicyParameter where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MechanicalTurk.Types.ParameterMapEntry
import qualified Amazonka.Prelude as Prelude

-- | Name of the parameter from the Review policy.
--
-- /See:/ 'newPolicyParameter' smart constructor.
data PolicyParameter = PolicyParameter'
  { -- | The list of values of the Parameter
    PolicyParameter -> Maybe [Text]
values :: Prelude.Maybe [Prelude.Text],
    -- | List of ParameterMapEntry objects.
    PolicyParameter -> Maybe [ParameterMapEntry]
mapEntries :: Prelude.Maybe [ParameterMapEntry],
    -- | Name of the parameter from the list of Review Polices.
    PolicyParameter -> Maybe Text
key :: Prelude.Maybe Prelude.Text
  }
  deriving (PolicyParameter -> PolicyParameter -> Bool
(PolicyParameter -> PolicyParameter -> Bool)
-> (PolicyParameter -> PolicyParameter -> Bool)
-> Eq PolicyParameter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PolicyParameter -> PolicyParameter -> Bool
$c/= :: PolicyParameter -> PolicyParameter -> Bool
== :: PolicyParameter -> PolicyParameter -> Bool
$c== :: PolicyParameter -> PolicyParameter -> Bool
Prelude.Eq, ReadPrec [PolicyParameter]
ReadPrec PolicyParameter
Int -> ReadS PolicyParameter
ReadS [PolicyParameter]
(Int -> ReadS PolicyParameter)
-> ReadS [PolicyParameter]
-> ReadPrec PolicyParameter
-> ReadPrec [PolicyParameter]
-> Read PolicyParameter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PolicyParameter]
$creadListPrec :: ReadPrec [PolicyParameter]
readPrec :: ReadPrec PolicyParameter
$creadPrec :: ReadPrec PolicyParameter
readList :: ReadS [PolicyParameter]
$creadList :: ReadS [PolicyParameter]
readsPrec :: Int -> ReadS PolicyParameter
$creadsPrec :: Int -> ReadS PolicyParameter
Prelude.Read, Int -> PolicyParameter -> ShowS
[PolicyParameter] -> ShowS
PolicyParameter -> String
(Int -> PolicyParameter -> ShowS)
-> (PolicyParameter -> String)
-> ([PolicyParameter] -> ShowS)
-> Show PolicyParameter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PolicyParameter] -> ShowS
$cshowList :: [PolicyParameter] -> ShowS
show :: PolicyParameter -> String
$cshow :: PolicyParameter -> String
showsPrec :: Int -> PolicyParameter -> ShowS
$cshowsPrec :: Int -> PolicyParameter -> ShowS
Prelude.Show, (forall x. PolicyParameter -> Rep PolicyParameter x)
-> (forall x. Rep PolicyParameter x -> PolicyParameter)
-> Generic PolicyParameter
forall x. Rep PolicyParameter x -> PolicyParameter
forall x. PolicyParameter -> Rep PolicyParameter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PolicyParameter x -> PolicyParameter
$cfrom :: forall x. PolicyParameter -> Rep PolicyParameter x
Prelude.Generic)

-- |
-- Create a value of 'PolicyParameter' 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:
--
-- 'values', 'policyParameter_values' - The list of values of the Parameter
--
-- 'mapEntries', 'policyParameter_mapEntries' - List of ParameterMapEntry objects.
--
-- 'key', 'policyParameter_key' - Name of the parameter from the list of Review Polices.
newPolicyParameter ::
  PolicyParameter
newPolicyParameter :: PolicyParameter
newPolicyParameter =
  PolicyParameter' :: Maybe [Text]
-> Maybe [ParameterMapEntry] -> Maybe Text -> PolicyParameter
PolicyParameter'
    { $sel:values:PolicyParameter' :: Maybe [Text]
values = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:mapEntries:PolicyParameter' :: Maybe [ParameterMapEntry]
mapEntries = Maybe [ParameterMapEntry]
forall a. Maybe a
Prelude.Nothing,
      $sel:key:PolicyParameter' :: Maybe Text
key = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The list of values of the Parameter
policyParameter_values :: Lens.Lens' PolicyParameter (Prelude.Maybe [Prelude.Text])
policyParameter_values :: (Maybe [Text] -> f (Maybe [Text]))
-> PolicyParameter -> f PolicyParameter
policyParameter_values = (PolicyParameter -> Maybe [Text])
-> (PolicyParameter -> Maybe [Text] -> PolicyParameter)
-> Lens
     PolicyParameter PolicyParameter (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyParameter' {Maybe [Text]
values :: Maybe [Text]
$sel:values:PolicyParameter' :: PolicyParameter -> Maybe [Text]
values} -> Maybe [Text]
values) (\s :: PolicyParameter
s@PolicyParameter' {} Maybe [Text]
a -> PolicyParameter
s {$sel:values:PolicyParameter' :: Maybe [Text]
values = Maybe [Text]
a} :: PolicyParameter) ((Maybe [Text] -> f (Maybe [Text]))
 -> PolicyParameter -> f PolicyParameter)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> PolicyParameter
-> f PolicyParameter
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | List of ParameterMapEntry objects.
policyParameter_mapEntries :: Lens.Lens' PolicyParameter (Prelude.Maybe [ParameterMapEntry])
policyParameter_mapEntries :: (Maybe [ParameterMapEntry] -> f (Maybe [ParameterMapEntry]))
-> PolicyParameter -> f PolicyParameter
policyParameter_mapEntries = (PolicyParameter -> Maybe [ParameterMapEntry])
-> (PolicyParameter
    -> Maybe [ParameterMapEntry] -> PolicyParameter)
-> Lens
     PolicyParameter
     PolicyParameter
     (Maybe [ParameterMapEntry])
     (Maybe [ParameterMapEntry])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyParameter' {Maybe [ParameterMapEntry]
mapEntries :: Maybe [ParameterMapEntry]
$sel:mapEntries:PolicyParameter' :: PolicyParameter -> Maybe [ParameterMapEntry]
mapEntries} -> Maybe [ParameterMapEntry]
mapEntries) (\s :: PolicyParameter
s@PolicyParameter' {} Maybe [ParameterMapEntry]
a -> PolicyParameter
s {$sel:mapEntries:PolicyParameter' :: Maybe [ParameterMapEntry]
mapEntries = Maybe [ParameterMapEntry]
a} :: PolicyParameter) ((Maybe [ParameterMapEntry] -> f (Maybe [ParameterMapEntry]))
 -> PolicyParameter -> f PolicyParameter)
-> ((Maybe [ParameterMapEntry] -> f (Maybe [ParameterMapEntry]))
    -> Maybe [ParameterMapEntry] -> f (Maybe [ParameterMapEntry]))
-> (Maybe [ParameterMapEntry] -> f (Maybe [ParameterMapEntry]))
-> PolicyParameter
-> f PolicyParameter
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [ParameterMapEntry]
  [ParameterMapEntry]
  [ParameterMapEntry]
  [ParameterMapEntry]
-> Iso
     (Maybe [ParameterMapEntry])
     (Maybe [ParameterMapEntry])
     (Maybe [ParameterMapEntry])
     (Maybe [ParameterMapEntry])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [ParameterMapEntry]
  [ParameterMapEntry]
  [ParameterMapEntry]
  [ParameterMapEntry]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Name of the parameter from the list of Review Polices.
policyParameter_key :: Lens.Lens' PolicyParameter (Prelude.Maybe Prelude.Text)
policyParameter_key :: (Maybe Text -> f (Maybe Text))
-> PolicyParameter -> f PolicyParameter
policyParameter_key = (PolicyParameter -> Maybe Text)
-> (PolicyParameter -> Maybe Text -> PolicyParameter)
-> Lens PolicyParameter PolicyParameter (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyParameter' {Maybe Text
key :: Maybe Text
$sel:key:PolicyParameter' :: PolicyParameter -> Maybe Text
key} -> Maybe Text
key) (\s :: PolicyParameter
s@PolicyParameter' {} Maybe Text
a -> PolicyParameter
s {$sel:key:PolicyParameter' :: Maybe Text
key = Maybe Text
a} :: PolicyParameter)

instance Core.FromJSON PolicyParameter where
  parseJSON :: Value -> Parser PolicyParameter
parseJSON =
    String
-> (Object -> Parser PolicyParameter)
-> Value
-> Parser PolicyParameter
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PolicyParameter"
      ( \Object
x ->
          Maybe [Text]
-> Maybe [ParameterMapEntry] -> Maybe Text -> PolicyParameter
PolicyParameter'
            (Maybe [Text]
 -> Maybe [ParameterMapEntry] -> Maybe Text -> PolicyParameter)
-> Parser (Maybe [Text])
-> Parser
     (Maybe [ParameterMapEntry] -> Maybe Text -> PolicyParameter)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Values" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe [ParameterMapEntry] -> Maybe Text -> PolicyParameter)
-> Parser (Maybe [ParameterMapEntry])
-> Parser (Maybe Text -> PolicyParameter)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [ParameterMapEntry]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MapEntries" Parser (Maybe (Maybe [ParameterMapEntry]))
-> Maybe [ParameterMapEntry] -> Parser (Maybe [ParameterMapEntry])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [ParameterMapEntry]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> PolicyParameter)
-> Parser (Maybe Text) -> Parser PolicyParameter
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Key")
      )

instance Prelude.Hashable PolicyParameter

instance Prelude.NFData PolicyParameter

instance Core.ToJSON PolicyParameter where
  toJSON :: PolicyParameter -> Value
toJSON PolicyParameter' {Maybe [Text]
Maybe [ParameterMapEntry]
Maybe Text
key :: Maybe Text
mapEntries :: Maybe [ParameterMapEntry]
values :: Maybe [Text]
$sel:key:PolicyParameter' :: PolicyParameter -> Maybe Text
$sel:mapEntries:PolicyParameter' :: PolicyParameter -> Maybe [ParameterMapEntry]
$sel:values:PolicyParameter' :: PolicyParameter -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Values" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
values,
            (Text
"MapEntries" Text -> [ParameterMapEntry] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([ParameterMapEntry] -> Pair)
-> Maybe [ParameterMapEntry] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [ParameterMapEntry]
mapEntries,
            (Text
"Key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
key
          ]
      )