{-# 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.AppConfig.Types.Validator
-- 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.AppConfig.Types.Validator where

import Amazonka.AppConfig.Types.ValidatorType
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | A validator provides a syntactic or semantic check to ensure the
-- configuration that you want to deploy functions as intended. To validate
-- your application configuration data, you provide a schema or an Amazon
-- Web Services Lambda function that runs against the configuration. The
-- configuration deployment or update can only proceed when the
-- configuration data is valid.
--
-- /See:/ 'newValidator' smart constructor.
data Validator = Validator'
  { -- | AppConfig supports validators of type @JSON_SCHEMA@ and @LAMBDA@
    Validator -> ValidatorType
type' :: ValidatorType,
    -- | Either the JSON Schema content or the Amazon Resource Name (ARN) of an
    -- Lambda function.
    Validator -> Sensitive Text
content :: Data.Sensitive Prelude.Text
  }
  deriving (Validator -> Validator -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Validator -> Validator -> Bool
$c/= :: Validator -> Validator -> Bool
== :: Validator -> Validator -> Bool
$c== :: Validator -> Validator -> Bool
Prelude.Eq, Int -> Validator -> ShowS
[Validator] -> ShowS
Validator -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Validator] -> ShowS
$cshowList :: [Validator] -> ShowS
show :: Validator -> String
$cshow :: Validator -> String
showsPrec :: Int -> Validator -> ShowS
$cshowsPrec :: Int -> Validator -> ShowS
Prelude.Show, forall x. Rep Validator x -> Validator
forall x. Validator -> Rep Validator x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Validator x -> Validator
$cfrom :: forall x. Validator -> Rep Validator x
Prelude.Generic)

-- |
-- Create a value of 'Validator' 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'', 'validator_type' - AppConfig supports validators of type @JSON_SCHEMA@ and @LAMBDA@
--
-- 'content', 'validator_content' - Either the JSON Schema content or the Amazon Resource Name (ARN) of an
-- Lambda function.
newValidator ::
  -- | 'type''
  ValidatorType ->
  -- | 'content'
  Prelude.Text ->
  Validator
newValidator :: ValidatorType -> Text -> Validator
newValidator ValidatorType
pType_ Text
pContent_ =
  Validator'
    { $sel:type':Validator' :: ValidatorType
type' = ValidatorType
pType_,
      $sel:content:Validator' :: Sensitive Text
content = forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pContent_
    }

-- | AppConfig supports validators of type @JSON_SCHEMA@ and @LAMBDA@
validator_type :: Lens.Lens' Validator ValidatorType
validator_type :: Lens' Validator ValidatorType
validator_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Validator' {ValidatorType
type' :: ValidatorType
$sel:type':Validator' :: Validator -> ValidatorType
type'} -> ValidatorType
type') (\s :: Validator
s@Validator' {} ValidatorType
a -> Validator
s {$sel:type':Validator' :: ValidatorType
type' = ValidatorType
a} :: Validator)

-- | Either the JSON Schema content or the Amazon Resource Name (ARN) of an
-- Lambda function.
validator_content :: Lens.Lens' Validator Prelude.Text
validator_content :: Lens' Validator Text
validator_content = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Validator' {Sensitive Text
content :: Sensitive Text
$sel:content:Validator' :: Validator -> Sensitive Text
content} -> Sensitive Text
content) (\s :: Validator
s@Validator' {} Sensitive Text
a -> Validator
s {$sel:content:Validator' :: Sensitive Text
content = Sensitive Text
a} :: Validator) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Data.FromJSON Validator where
  parseJSON :: Value -> Parser Validator
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Validator"
      ( \Object
x ->
          ValidatorType -> Sensitive Text -> Validator
Validator'
            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 a
Data..: Key
"Content")
      )

instance Prelude.Hashable Validator where
  hashWithSalt :: Int -> Validator -> Int
hashWithSalt Int
_salt Validator' {Sensitive Text
ValidatorType
content :: Sensitive Text
type' :: ValidatorType
$sel:content:Validator' :: Validator -> Sensitive Text
$sel:type':Validator' :: Validator -> ValidatorType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ValidatorType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
content

instance Prelude.NFData Validator where
  rnf :: Validator -> ()
rnf Validator' {Sensitive Text
ValidatorType
content :: Sensitive Text
type' :: ValidatorType
$sel:content:Validator' :: Validator -> Sensitive Text
$sel:type':Validator' :: Validator -> ValidatorType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf ValidatorType
type' seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
content

instance Data.ToJSON Validator where
  toJSON :: Validator -> Value
toJSON Validator' {Sensitive Text
ValidatorType
content :: Sensitive Text
type' :: ValidatorType
$sel:content:Validator' :: Validator -> Sensitive Text
$sel:type':Validator' :: Validator -> ValidatorType
..} =
    [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..= ValidatorType
type'),
            forall a. a -> Maybe a
Prelude.Just (Key
"Content" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
content)
          ]
      )