{-# 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.DataBrew.Types.Threshold
-- 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.DataBrew.Types.Threshold where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DataBrew.Types.ThresholdType
import Amazonka.DataBrew.Types.ThresholdUnit
import qualified Amazonka.Prelude as Prelude

-- | The threshold used with a non-aggregate check expression. The
-- non-aggregate check expression will be applied to each row in a specific
-- column. Then the threshold will be used to determine whether the
-- validation succeeds.
--
-- /See:/ 'newThreshold' smart constructor.
data Threshold = Threshold'
  { -- | The type of a threshold. Used for comparison of an actual count of rows
    -- that satisfy the rule to the threshold value.
    Threshold -> Maybe ThresholdType
type' :: Prelude.Maybe ThresholdType,
    -- | Unit of threshold value. Can be either a COUNT or PERCENTAGE of the full
    -- sample size used for validation.
    Threshold -> Maybe ThresholdUnit
unit :: Prelude.Maybe ThresholdUnit,
    -- | The value of a threshold.
    Threshold -> Double
value :: Prelude.Double
  }
  deriving (Threshold -> Threshold -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Threshold -> Threshold -> Bool
$c/= :: Threshold -> Threshold -> Bool
== :: Threshold -> Threshold -> Bool
$c== :: Threshold -> Threshold -> Bool
Prelude.Eq, ReadPrec [Threshold]
ReadPrec Threshold
Int -> ReadS Threshold
ReadS [Threshold]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Threshold]
$creadListPrec :: ReadPrec [Threshold]
readPrec :: ReadPrec Threshold
$creadPrec :: ReadPrec Threshold
readList :: ReadS [Threshold]
$creadList :: ReadS [Threshold]
readsPrec :: Int -> ReadS Threshold
$creadsPrec :: Int -> ReadS Threshold
Prelude.Read, Int -> Threshold -> ShowS
[Threshold] -> ShowS
Threshold -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Threshold] -> ShowS
$cshowList :: [Threshold] -> ShowS
show :: Threshold -> String
$cshow :: Threshold -> String
showsPrec :: Int -> Threshold -> ShowS
$cshowsPrec :: Int -> Threshold -> ShowS
Prelude.Show, forall x. Rep Threshold x -> Threshold
forall x. Threshold -> Rep Threshold x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Threshold x -> Threshold
$cfrom :: forall x. Threshold -> Rep Threshold x
Prelude.Generic)

-- |
-- Create a value of 'Threshold' 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'', 'threshold_type' - The type of a threshold. Used for comparison of an actual count of rows
-- that satisfy the rule to the threshold value.
--
-- 'unit', 'threshold_unit' - Unit of threshold value. Can be either a COUNT or PERCENTAGE of the full
-- sample size used for validation.
--
-- 'value', 'threshold_value' - The value of a threshold.
newThreshold ::
  -- | 'value'
  Prelude.Double ->
  Threshold
newThreshold :: Double -> Threshold
newThreshold Double
pValue_ =
  Threshold'
    { $sel:type':Threshold' :: Maybe ThresholdType
type' = forall a. Maybe a
Prelude.Nothing,
      $sel:unit:Threshold' :: Maybe ThresholdUnit
unit = forall a. Maybe a
Prelude.Nothing,
      $sel:value:Threshold' :: Double
value = Double
pValue_
    }

-- | The type of a threshold. Used for comparison of an actual count of rows
-- that satisfy the rule to the threshold value.
threshold_type :: Lens.Lens' Threshold (Prelude.Maybe ThresholdType)
threshold_type :: Lens' Threshold (Maybe ThresholdType)
threshold_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Threshold' {Maybe ThresholdType
type' :: Maybe ThresholdType
$sel:type':Threshold' :: Threshold -> Maybe ThresholdType
type'} -> Maybe ThresholdType
type') (\s :: Threshold
s@Threshold' {} Maybe ThresholdType
a -> Threshold
s {$sel:type':Threshold' :: Maybe ThresholdType
type' = Maybe ThresholdType
a} :: Threshold)

-- | Unit of threshold value. Can be either a COUNT or PERCENTAGE of the full
-- sample size used for validation.
threshold_unit :: Lens.Lens' Threshold (Prelude.Maybe ThresholdUnit)
threshold_unit :: Lens' Threshold (Maybe ThresholdUnit)
threshold_unit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Threshold' {Maybe ThresholdUnit
unit :: Maybe ThresholdUnit
$sel:unit:Threshold' :: Threshold -> Maybe ThresholdUnit
unit} -> Maybe ThresholdUnit
unit) (\s :: Threshold
s@Threshold' {} Maybe ThresholdUnit
a -> Threshold
s {$sel:unit:Threshold' :: Maybe ThresholdUnit
unit = Maybe ThresholdUnit
a} :: Threshold)

-- | The value of a threshold.
threshold_value :: Lens.Lens' Threshold Prelude.Double
threshold_value :: Lens' Threshold Double
threshold_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Threshold' {Double
value :: Double
$sel:value:Threshold' :: Threshold -> Double
value} -> Double
value) (\s :: Threshold
s@Threshold' {} Double
a -> Threshold
s {$sel:value:Threshold' :: Double
value = Double
a} :: Threshold)

instance Data.FromJSON Threshold where
  parseJSON :: Value -> Parser Threshold
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Threshold"
      ( \Object
x ->
          Maybe ThresholdType -> Maybe ThresholdUnit -> Double -> Threshold
Threshold'
            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
"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
"Unit")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Value")
      )

instance Prelude.Hashable Threshold where
  hashWithSalt :: Int -> Threshold -> Int
hashWithSalt Int
_salt Threshold' {Double
Maybe ThresholdType
Maybe ThresholdUnit
value :: Double
unit :: Maybe ThresholdUnit
type' :: Maybe ThresholdType
$sel:value:Threshold' :: Threshold -> Double
$sel:unit:Threshold' :: Threshold -> Maybe ThresholdUnit
$sel:type':Threshold' :: Threshold -> Maybe ThresholdType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ThresholdType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ThresholdUnit
unit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
value

instance Prelude.NFData Threshold where
  rnf :: Threshold -> ()
rnf Threshold' {Double
Maybe ThresholdType
Maybe ThresholdUnit
value :: Double
unit :: Maybe ThresholdUnit
type' :: Maybe ThresholdType
$sel:value:Threshold' :: Threshold -> Double
$sel:unit:Threshold' :: Threshold -> Maybe ThresholdUnit
$sel:type':Threshold' :: Threshold -> Maybe ThresholdType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ThresholdType
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ThresholdUnit
unit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Double
value

instance Data.ToJSON Threshold where
  toJSON :: Threshold -> Value
toJSON Threshold' {Double
Maybe ThresholdType
Maybe ThresholdUnit
value :: Double
unit :: Maybe ThresholdUnit
type' :: Maybe ThresholdType
$sel:value:Threshold' :: Threshold -> Double
$sel:unit:Threshold' :: Threshold -> Maybe ThresholdUnit
$sel:type':Threshold' :: Threshold -> Maybe ThresholdType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Type" 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 ThresholdType
type',
            (Key
"Unit" 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 ThresholdUnit
unit,
            forall a. a -> Maybe a
Prelude.Just (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Double
value)
          ]
      )