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

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

-- | A validator provides a syntactic or semantic check to ensure the
-- configuration you want to deploy functions as intended. To validate your
-- application configuration data, you provide a schema or a 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
    -- AWS Lambda function.
    Validator -> Sensitive Text
content :: Core.Sensitive Prelude.Text
  }
  deriving (Validator -> Validator -> Bool
(Validator -> Validator -> Bool)
-> (Validator -> Validator -> Bool) -> Eq Validator
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
(Int -> Validator -> ShowS)
-> (Validator -> String)
-> ([Validator] -> ShowS)
-> Show Validator
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. Validator -> Rep Validator x)
-> (forall x. Rep Validator x -> Validator) -> Generic Validator
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
-- AWS Lambda function.
newValidator ::
  -- | 'type''
  ValidatorType ->
  -- | 'content'
  Prelude.Text ->
  Validator
newValidator :: ValidatorType -> Text -> Validator
newValidator ValidatorType
pType_ Text
pContent_ =
  Validator' :: ValidatorType -> Sensitive Text -> Validator
Validator'
    { $sel:type':Validator' :: ValidatorType
type' = ValidatorType
pType_,
      $sel:content:Validator' :: Sensitive Text
content = Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
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 :: (ValidatorType -> f ValidatorType) -> Validator -> f Validator
validator_type = (Validator -> ValidatorType)
-> (Validator -> ValidatorType -> Validator)
-> Lens Validator Validator ValidatorType ValidatorType
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
-- AWS Lambda function.
validator_content :: Lens.Lens' Validator Prelude.Text
validator_content :: (Text -> f Text) -> Validator -> f Validator
validator_content = (Validator -> Sensitive Text)
-> (Validator -> Sensitive Text -> Validator)
-> Lens Validator Validator (Sensitive Text) (Sensitive Text)
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) ((Sensitive Text -> f (Sensitive Text))
 -> Validator -> f Validator)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> Validator
-> f Validator
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

instance Core.FromJSON Validator where
  parseJSON :: Value -> Parser Validator
parseJSON =
    String -> (Object -> Parser Validator) -> Value -> Parser Validator
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Validator"
      ( \Object
x ->
          ValidatorType -> Sensitive Text -> Validator
Validator'
            (ValidatorType -> Sensitive Text -> Validator)
-> Parser ValidatorType -> Parser (Sensitive Text -> Validator)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser ValidatorType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type") Parser (Sensitive Text -> Validator)
-> Parser (Sensitive Text) -> Parser Validator
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Sensitive Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Content")
      )

instance Prelude.Hashable Validator

instance Prelude.NFData Validator

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> ValidatorType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ValidatorType
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Content" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
content)
          ]
      )