{-# 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.CertificateManagerPCA.Types.CustomExtension
-- 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.CertificateManagerPCA.Types.CustomExtension where

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

-- | Specifies the X.509 extension information for a certificate.
--
-- Extensions present in @CustomExtensions@ follow the @ApiPassthrough@
-- <https://docs.aws.amazon.com/privateca/latest/userguide/UsingTemplates.html#template-order-of-operations template rules>.
--
-- /See:/ 'newCustomExtension' smart constructor.
data CustomExtension = CustomExtension'
  { -- | Specifies the critical flag of the X.509 extension.
    CustomExtension -> Maybe Bool
critical :: Prelude.Maybe Prelude.Bool,
    -- | Specifies the object identifier (OID) of the X.509 extension. For more
    -- information, see the
    -- <https://oidref.com/2.5.29 Global OID reference database.>
    CustomExtension -> Text
objectIdentifier :: Prelude.Text,
    -- | Specifies the base64-encoded value of the X.509 extension.
    CustomExtension -> Text
value :: Prelude.Text
  }
  deriving (CustomExtension -> CustomExtension -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomExtension -> CustomExtension -> Bool
$c/= :: CustomExtension -> CustomExtension -> Bool
== :: CustomExtension -> CustomExtension -> Bool
$c== :: CustomExtension -> CustomExtension -> Bool
Prelude.Eq, ReadPrec [CustomExtension]
ReadPrec CustomExtension
Int -> ReadS CustomExtension
ReadS [CustomExtension]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomExtension]
$creadListPrec :: ReadPrec [CustomExtension]
readPrec :: ReadPrec CustomExtension
$creadPrec :: ReadPrec CustomExtension
readList :: ReadS [CustomExtension]
$creadList :: ReadS [CustomExtension]
readsPrec :: Int -> ReadS CustomExtension
$creadsPrec :: Int -> ReadS CustomExtension
Prelude.Read, Int -> CustomExtension -> ShowS
[CustomExtension] -> ShowS
CustomExtension -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomExtension] -> ShowS
$cshowList :: [CustomExtension] -> ShowS
show :: CustomExtension -> String
$cshow :: CustomExtension -> String
showsPrec :: Int -> CustomExtension -> ShowS
$cshowsPrec :: Int -> CustomExtension -> ShowS
Prelude.Show, forall x. Rep CustomExtension x -> CustomExtension
forall x. CustomExtension -> Rep CustomExtension x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomExtension x -> CustomExtension
$cfrom :: forall x. CustomExtension -> Rep CustomExtension x
Prelude.Generic)

-- |
-- Create a value of 'CustomExtension' 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:
--
-- 'critical', 'customExtension_critical' - Specifies the critical flag of the X.509 extension.
--
-- 'objectIdentifier', 'customExtension_objectIdentifier' - Specifies the object identifier (OID) of the X.509 extension. For more
-- information, see the
-- <https://oidref.com/2.5.29 Global OID reference database.>
--
-- 'value', 'customExtension_value' - Specifies the base64-encoded value of the X.509 extension.
newCustomExtension ::
  -- | 'objectIdentifier'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  CustomExtension
newCustomExtension :: Text -> Text -> CustomExtension
newCustomExtension Text
pObjectIdentifier_ Text
pValue_ =
  CustomExtension'
    { $sel:critical:CustomExtension' :: Maybe Bool
critical = forall a. Maybe a
Prelude.Nothing,
      $sel:objectIdentifier:CustomExtension' :: Text
objectIdentifier = Text
pObjectIdentifier_,
      $sel:value:CustomExtension' :: Text
value = Text
pValue_
    }

-- | Specifies the critical flag of the X.509 extension.
customExtension_critical :: Lens.Lens' CustomExtension (Prelude.Maybe Prelude.Bool)
customExtension_critical :: Lens' CustomExtension (Maybe Bool)
customExtension_critical = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomExtension' {Maybe Bool
critical :: Maybe Bool
$sel:critical:CustomExtension' :: CustomExtension -> Maybe Bool
critical} -> Maybe Bool
critical) (\s :: CustomExtension
s@CustomExtension' {} Maybe Bool
a -> CustomExtension
s {$sel:critical:CustomExtension' :: Maybe Bool
critical = Maybe Bool
a} :: CustomExtension)

-- | Specifies the object identifier (OID) of the X.509 extension. For more
-- information, see the
-- <https://oidref.com/2.5.29 Global OID reference database.>
customExtension_objectIdentifier :: Lens.Lens' CustomExtension Prelude.Text
customExtension_objectIdentifier :: Lens' CustomExtension Text
customExtension_objectIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomExtension' {Text
objectIdentifier :: Text
$sel:objectIdentifier:CustomExtension' :: CustomExtension -> Text
objectIdentifier} -> Text
objectIdentifier) (\s :: CustomExtension
s@CustomExtension' {} Text
a -> CustomExtension
s {$sel:objectIdentifier:CustomExtension' :: Text
objectIdentifier = Text
a} :: CustomExtension)

-- | Specifies the base64-encoded value of the X.509 extension.
customExtension_value :: Lens.Lens' CustomExtension Prelude.Text
customExtension_value :: Lens' CustomExtension Text
customExtension_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomExtension' {Text
value :: Text
$sel:value:CustomExtension' :: CustomExtension -> Text
value} -> Text
value) (\s :: CustomExtension
s@CustomExtension' {} Text
a -> CustomExtension
s {$sel:value:CustomExtension' :: Text
value = Text
a} :: CustomExtension)

instance Prelude.Hashable CustomExtension where
  hashWithSalt :: Int -> CustomExtension -> Int
hashWithSalt Int
_salt CustomExtension' {Maybe Bool
Text
value :: Text
objectIdentifier :: Text
critical :: Maybe Bool
$sel:value:CustomExtension' :: CustomExtension -> Text
$sel:objectIdentifier:CustomExtension' :: CustomExtension -> Text
$sel:critical:CustomExtension' :: CustomExtension -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
critical
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
objectIdentifier
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value

instance Prelude.NFData CustomExtension where
  rnf :: CustomExtension -> ()
rnf CustomExtension' {Maybe Bool
Text
value :: Text
objectIdentifier :: Text
critical :: Maybe Bool
$sel:value:CustomExtension' :: CustomExtension -> Text
$sel:objectIdentifier:CustomExtension' :: CustomExtension -> Text
$sel:critical:CustomExtension' :: CustomExtension -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
critical
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
objectIdentifier
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
value

instance Data.ToJSON CustomExtension where
  toJSON :: CustomExtension -> Value
toJSON CustomExtension' {Maybe Bool
Text
value :: Text
objectIdentifier :: Text
critical :: Maybe Bool
$sel:value:CustomExtension' :: CustomExtension -> Text
$sel:objectIdentifier:CustomExtension' :: CustomExtension -> Text
$sel:critical:CustomExtension' :: CustomExtension -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Critical" 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 Bool
critical,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ObjectIdentifier" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
objectIdentifier),
            forall a. a -> Maybe a
Prelude.Just (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
value)
          ]
      )