{-# 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.SecurityHub.Types.Adjustment
-- 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.SecurityHub.Types.Adjustment where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An adjustment to the CVSS metric.
--
-- /See:/ 'newAdjustment' smart constructor.
data Adjustment = Adjustment'
  { -- | The reason for the adjustment.
    Adjustment -> Maybe Text
reason :: Prelude.Maybe Prelude.Text,
    -- | The metric to adjust.
    Adjustment -> Maybe Text
metric :: Prelude.Maybe Prelude.Text
  }
  deriving (Adjustment -> Adjustment -> Bool
(Adjustment -> Adjustment -> Bool)
-> (Adjustment -> Adjustment -> Bool) -> Eq Adjustment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Adjustment -> Adjustment -> Bool
$c/= :: Adjustment -> Adjustment -> Bool
== :: Adjustment -> Adjustment -> Bool
$c== :: Adjustment -> Adjustment -> Bool
Prelude.Eq, ReadPrec [Adjustment]
ReadPrec Adjustment
Int -> ReadS Adjustment
ReadS [Adjustment]
(Int -> ReadS Adjustment)
-> ReadS [Adjustment]
-> ReadPrec Adjustment
-> ReadPrec [Adjustment]
-> Read Adjustment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Adjustment]
$creadListPrec :: ReadPrec [Adjustment]
readPrec :: ReadPrec Adjustment
$creadPrec :: ReadPrec Adjustment
readList :: ReadS [Adjustment]
$creadList :: ReadS [Adjustment]
readsPrec :: Int -> ReadS Adjustment
$creadsPrec :: Int -> ReadS Adjustment
Prelude.Read, Int -> Adjustment -> ShowS
[Adjustment] -> ShowS
Adjustment -> String
(Int -> Adjustment -> ShowS)
-> (Adjustment -> String)
-> ([Adjustment] -> ShowS)
-> Show Adjustment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Adjustment] -> ShowS
$cshowList :: [Adjustment] -> ShowS
show :: Adjustment -> String
$cshow :: Adjustment -> String
showsPrec :: Int -> Adjustment -> ShowS
$cshowsPrec :: Int -> Adjustment -> ShowS
Prelude.Show, (forall x. Adjustment -> Rep Adjustment x)
-> (forall x. Rep Adjustment x -> Adjustment) -> Generic Adjustment
forall x. Rep Adjustment x -> Adjustment
forall x. Adjustment -> Rep Adjustment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Adjustment x -> Adjustment
$cfrom :: forall x. Adjustment -> Rep Adjustment x
Prelude.Generic)

-- |
-- Create a value of 'Adjustment' 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:
--
-- 'reason', 'adjustment_reason' - The reason for the adjustment.
--
-- 'metric', 'adjustment_metric' - The metric to adjust.
newAdjustment ::
  Adjustment
newAdjustment :: Adjustment
newAdjustment =
  Adjustment' :: Maybe Text -> Maybe Text -> Adjustment
Adjustment'
    { $sel:reason:Adjustment' :: Maybe Text
reason = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:metric:Adjustment' :: Maybe Text
metric = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The reason for the adjustment.
adjustment_reason :: Lens.Lens' Adjustment (Prelude.Maybe Prelude.Text)
adjustment_reason :: (Maybe Text -> f (Maybe Text)) -> Adjustment -> f Adjustment
adjustment_reason = (Adjustment -> Maybe Text)
-> (Adjustment -> Maybe Text -> Adjustment)
-> Lens Adjustment Adjustment (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Adjustment' {Maybe Text
reason :: Maybe Text
$sel:reason:Adjustment' :: Adjustment -> Maybe Text
reason} -> Maybe Text
reason) (\s :: Adjustment
s@Adjustment' {} Maybe Text
a -> Adjustment
s {$sel:reason:Adjustment' :: Maybe Text
reason = Maybe Text
a} :: Adjustment)

-- | The metric to adjust.
adjustment_metric :: Lens.Lens' Adjustment (Prelude.Maybe Prelude.Text)
adjustment_metric :: (Maybe Text -> f (Maybe Text)) -> Adjustment -> f Adjustment
adjustment_metric = (Adjustment -> Maybe Text)
-> (Adjustment -> Maybe Text -> Adjustment)
-> Lens Adjustment Adjustment (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Adjustment' {Maybe Text
metric :: Maybe Text
$sel:metric:Adjustment' :: Adjustment -> Maybe Text
metric} -> Maybe Text
metric) (\s :: Adjustment
s@Adjustment' {} Maybe Text
a -> Adjustment
s {$sel:metric:Adjustment' :: Maybe Text
metric = Maybe Text
a} :: Adjustment)

instance Core.FromJSON Adjustment where
  parseJSON :: Value -> Parser Adjustment
parseJSON =
    String
-> (Object -> Parser Adjustment) -> Value -> Parser Adjustment
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Adjustment"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Adjustment
Adjustment'
            (Maybe Text -> Maybe Text -> Adjustment)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Adjustment)
forall (f :: * -> *) a b. Functor 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
"Reason")
            Parser (Maybe Text -> Adjustment)
-> Parser (Maybe Text) -> Parser Adjustment
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
"Metric")
      )

instance Prelude.Hashable Adjustment

instance Prelude.NFData Adjustment

instance Core.ToJSON Adjustment where
  toJSON :: Adjustment -> Value
toJSON Adjustment' {Maybe Text
metric :: Maybe Text
reason :: Maybe Text
$sel:metric:Adjustment' :: Adjustment -> Maybe Text
$sel:reason:Adjustment' :: Adjustment -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Reason" 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
reason,
            (Text
"Metric" 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
metric
          ]
      )