{-# 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.ReviewPolicy
-- 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.ReviewPolicy where

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

-- | HIT Review Policy data structures represent HIT review policies, which
-- you specify when you create a HIT.
--
-- /See:/ 'newReviewPolicy' smart constructor.
data ReviewPolicy = ReviewPolicy'
  { -- | Name of the parameter from the Review policy.
    ReviewPolicy -> Maybe [PolicyParameter]
parameters :: Prelude.Maybe [PolicyParameter],
    -- | Name of a Review Policy: SimplePlurality\/2011-09-01 or
    -- ScoreMyKnownAnswers\/2011-09-01
    ReviewPolicy -> Text
policyName :: Prelude.Text
  }
  deriving (ReviewPolicy -> ReviewPolicy -> Bool
(ReviewPolicy -> ReviewPolicy -> Bool)
-> (ReviewPolicy -> ReviewPolicy -> Bool) -> Eq ReviewPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReviewPolicy -> ReviewPolicy -> Bool
$c/= :: ReviewPolicy -> ReviewPolicy -> Bool
== :: ReviewPolicy -> ReviewPolicy -> Bool
$c== :: ReviewPolicy -> ReviewPolicy -> Bool
Prelude.Eq, ReadPrec [ReviewPolicy]
ReadPrec ReviewPolicy
Int -> ReadS ReviewPolicy
ReadS [ReviewPolicy]
(Int -> ReadS ReviewPolicy)
-> ReadS [ReviewPolicy]
-> ReadPrec ReviewPolicy
-> ReadPrec [ReviewPolicy]
-> Read ReviewPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReviewPolicy]
$creadListPrec :: ReadPrec [ReviewPolicy]
readPrec :: ReadPrec ReviewPolicy
$creadPrec :: ReadPrec ReviewPolicy
readList :: ReadS [ReviewPolicy]
$creadList :: ReadS [ReviewPolicy]
readsPrec :: Int -> ReadS ReviewPolicy
$creadsPrec :: Int -> ReadS ReviewPolicy
Prelude.Read, Int -> ReviewPolicy -> ShowS
[ReviewPolicy] -> ShowS
ReviewPolicy -> String
(Int -> ReviewPolicy -> ShowS)
-> (ReviewPolicy -> String)
-> ([ReviewPolicy] -> ShowS)
-> Show ReviewPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReviewPolicy] -> ShowS
$cshowList :: [ReviewPolicy] -> ShowS
show :: ReviewPolicy -> String
$cshow :: ReviewPolicy -> String
showsPrec :: Int -> ReviewPolicy -> ShowS
$cshowsPrec :: Int -> ReviewPolicy -> ShowS
Prelude.Show, (forall x. ReviewPolicy -> Rep ReviewPolicy x)
-> (forall x. Rep ReviewPolicy x -> ReviewPolicy)
-> Generic ReviewPolicy
forall x. Rep ReviewPolicy x -> ReviewPolicy
forall x. ReviewPolicy -> Rep ReviewPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReviewPolicy x -> ReviewPolicy
$cfrom :: forall x. ReviewPolicy -> Rep ReviewPolicy x
Prelude.Generic)

-- |
-- Create a value of 'ReviewPolicy' 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:
--
-- 'parameters', 'reviewPolicy_parameters' - Name of the parameter from the Review policy.
--
-- 'policyName', 'reviewPolicy_policyName' - Name of a Review Policy: SimplePlurality\/2011-09-01 or
-- ScoreMyKnownAnswers\/2011-09-01
newReviewPolicy ::
  -- | 'policyName'
  Prelude.Text ->
  ReviewPolicy
newReviewPolicy :: Text -> ReviewPolicy
newReviewPolicy Text
pPolicyName_ =
  ReviewPolicy' :: Maybe [PolicyParameter] -> Text -> ReviewPolicy
ReviewPolicy'
    { $sel:parameters:ReviewPolicy' :: Maybe [PolicyParameter]
parameters = Maybe [PolicyParameter]
forall a. Maybe a
Prelude.Nothing,
      $sel:policyName:ReviewPolicy' :: Text
policyName = Text
pPolicyName_
    }

-- | Name of the parameter from the Review policy.
reviewPolicy_parameters :: Lens.Lens' ReviewPolicy (Prelude.Maybe [PolicyParameter])
reviewPolicy_parameters :: (Maybe [PolicyParameter] -> f (Maybe [PolicyParameter]))
-> ReviewPolicy -> f ReviewPolicy
reviewPolicy_parameters = (ReviewPolicy -> Maybe [PolicyParameter])
-> (ReviewPolicy -> Maybe [PolicyParameter] -> ReviewPolicy)
-> Lens
     ReviewPolicy
     ReviewPolicy
     (Maybe [PolicyParameter])
     (Maybe [PolicyParameter])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReviewPolicy' {Maybe [PolicyParameter]
parameters :: Maybe [PolicyParameter]
$sel:parameters:ReviewPolicy' :: ReviewPolicy -> Maybe [PolicyParameter]
parameters} -> Maybe [PolicyParameter]
parameters) (\s :: ReviewPolicy
s@ReviewPolicy' {} Maybe [PolicyParameter]
a -> ReviewPolicy
s {$sel:parameters:ReviewPolicy' :: Maybe [PolicyParameter]
parameters = Maybe [PolicyParameter]
a} :: ReviewPolicy) ((Maybe [PolicyParameter] -> f (Maybe [PolicyParameter]))
 -> ReviewPolicy -> f ReviewPolicy)
-> ((Maybe [PolicyParameter] -> f (Maybe [PolicyParameter]))
    -> Maybe [PolicyParameter] -> f (Maybe [PolicyParameter]))
-> (Maybe [PolicyParameter] -> f (Maybe [PolicyParameter]))
-> ReviewPolicy
-> f ReviewPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PolicyParameter]
  [PolicyParameter]
  [PolicyParameter]
  [PolicyParameter]
-> Iso
     (Maybe [PolicyParameter])
     (Maybe [PolicyParameter])
     (Maybe [PolicyParameter])
     (Maybe [PolicyParameter])
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
  [PolicyParameter]
  [PolicyParameter]
  [PolicyParameter]
  [PolicyParameter]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Name of a Review Policy: SimplePlurality\/2011-09-01 or
-- ScoreMyKnownAnswers\/2011-09-01
reviewPolicy_policyName :: Lens.Lens' ReviewPolicy Prelude.Text
reviewPolicy_policyName :: (Text -> f Text) -> ReviewPolicy -> f ReviewPolicy
reviewPolicy_policyName = (ReviewPolicy -> Text)
-> (ReviewPolicy -> Text -> ReviewPolicy)
-> Lens ReviewPolicy ReviewPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReviewPolicy' {Text
policyName :: Text
$sel:policyName:ReviewPolicy' :: ReviewPolicy -> Text
policyName} -> Text
policyName) (\s :: ReviewPolicy
s@ReviewPolicy' {} Text
a -> ReviewPolicy
s {$sel:policyName:ReviewPolicy' :: Text
policyName = Text
a} :: ReviewPolicy)

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

instance Prelude.Hashable ReviewPolicy

instance Prelude.NFData ReviewPolicy

instance Core.ToJSON ReviewPolicy where
  toJSON :: ReviewPolicy -> Value
toJSON ReviewPolicy' {Maybe [PolicyParameter]
Text
policyName :: Text
parameters :: Maybe [PolicyParameter]
$sel:policyName:ReviewPolicy' :: ReviewPolicy -> Text
$sel:parameters:ReviewPolicy' :: ReviewPolicy -> Maybe [PolicyParameter]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Parameters" Text -> [PolicyParameter] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([PolicyParameter] -> Pair)
-> Maybe [PolicyParameter] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [PolicyParameter]
parameters,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PolicyName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
policyName)
          ]
      )