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

import Amazonka.CertificateManagerPCA.Types.AccessMethodType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the type and format of extension access. Only one of
-- @CustomObjectIdentifier@ or @AccessMethodType@ may be provided.
-- Providing both results in @InvalidArgsException@.
--
-- /See:/ 'newAccessMethod' smart constructor.
data AccessMethod = AccessMethod'
  { -- | Specifies the @AccessMethod@.
    AccessMethod -> Maybe AccessMethodType
accessMethodType :: Prelude.Maybe AccessMethodType,
    -- | An object identifier (OID) specifying the @AccessMethod@. The OID must
    -- satisfy the regular expression shown below. For more information, see
    -- NIST\'s definition of
    -- <https://csrc.nist.gov/glossary/term/Object_Identifier Object Identifier (OID)>.
    AccessMethod -> Maybe Text
customObjectIdentifier :: Prelude.Maybe Prelude.Text
  }
  deriving (AccessMethod -> AccessMethod -> Bool
(AccessMethod -> AccessMethod -> Bool)
-> (AccessMethod -> AccessMethod -> Bool) -> Eq AccessMethod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccessMethod -> AccessMethod -> Bool
$c/= :: AccessMethod -> AccessMethod -> Bool
== :: AccessMethod -> AccessMethod -> Bool
$c== :: AccessMethod -> AccessMethod -> Bool
Prelude.Eq, ReadPrec [AccessMethod]
ReadPrec AccessMethod
Int -> ReadS AccessMethod
ReadS [AccessMethod]
(Int -> ReadS AccessMethod)
-> ReadS [AccessMethod]
-> ReadPrec AccessMethod
-> ReadPrec [AccessMethod]
-> Read AccessMethod
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AccessMethod]
$creadListPrec :: ReadPrec [AccessMethod]
readPrec :: ReadPrec AccessMethod
$creadPrec :: ReadPrec AccessMethod
readList :: ReadS [AccessMethod]
$creadList :: ReadS [AccessMethod]
readsPrec :: Int -> ReadS AccessMethod
$creadsPrec :: Int -> ReadS AccessMethod
Prelude.Read, Int -> AccessMethod -> ShowS
[AccessMethod] -> ShowS
AccessMethod -> String
(Int -> AccessMethod -> ShowS)
-> (AccessMethod -> String)
-> ([AccessMethod] -> ShowS)
-> Show AccessMethod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccessMethod] -> ShowS
$cshowList :: [AccessMethod] -> ShowS
show :: AccessMethod -> String
$cshow :: AccessMethod -> String
showsPrec :: Int -> AccessMethod -> ShowS
$cshowsPrec :: Int -> AccessMethod -> ShowS
Prelude.Show, (forall x. AccessMethod -> Rep AccessMethod x)
-> (forall x. Rep AccessMethod x -> AccessMethod)
-> Generic AccessMethod
forall x. Rep AccessMethod x -> AccessMethod
forall x. AccessMethod -> Rep AccessMethod x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AccessMethod x -> AccessMethod
$cfrom :: forall x. AccessMethod -> Rep AccessMethod x
Prelude.Generic)

-- |
-- Create a value of 'AccessMethod' 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:
--
-- 'accessMethodType', 'accessMethod_accessMethodType' - Specifies the @AccessMethod@.
--
-- 'customObjectIdentifier', 'accessMethod_customObjectIdentifier' - An object identifier (OID) specifying the @AccessMethod@. The OID must
-- satisfy the regular expression shown below. For more information, see
-- NIST\'s definition of
-- <https://csrc.nist.gov/glossary/term/Object_Identifier Object Identifier (OID)>.
newAccessMethod ::
  AccessMethod
newAccessMethod :: AccessMethod
newAccessMethod =
  AccessMethod' :: Maybe AccessMethodType -> Maybe Text -> AccessMethod
AccessMethod'
    { $sel:accessMethodType:AccessMethod' :: Maybe AccessMethodType
accessMethodType = Maybe AccessMethodType
forall a. Maybe a
Prelude.Nothing,
      $sel:customObjectIdentifier:AccessMethod' :: Maybe Text
customObjectIdentifier = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the @AccessMethod@.
accessMethod_accessMethodType :: Lens.Lens' AccessMethod (Prelude.Maybe AccessMethodType)
accessMethod_accessMethodType :: (Maybe AccessMethodType -> f (Maybe AccessMethodType))
-> AccessMethod -> f AccessMethod
accessMethod_accessMethodType = (AccessMethod -> Maybe AccessMethodType)
-> (AccessMethod -> Maybe AccessMethodType -> AccessMethod)
-> Lens
     AccessMethod
     AccessMethod
     (Maybe AccessMethodType)
     (Maybe AccessMethodType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessMethod' {Maybe AccessMethodType
accessMethodType :: Maybe AccessMethodType
$sel:accessMethodType:AccessMethod' :: AccessMethod -> Maybe AccessMethodType
accessMethodType} -> Maybe AccessMethodType
accessMethodType) (\s :: AccessMethod
s@AccessMethod' {} Maybe AccessMethodType
a -> AccessMethod
s {$sel:accessMethodType:AccessMethod' :: Maybe AccessMethodType
accessMethodType = Maybe AccessMethodType
a} :: AccessMethod)

-- | An object identifier (OID) specifying the @AccessMethod@. The OID must
-- satisfy the regular expression shown below. For more information, see
-- NIST\'s definition of
-- <https://csrc.nist.gov/glossary/term/Object_Identifier Object Identifier (OID)>.
accessMethod_customObjectIdentifier :: Lens.Lens' AccessMethod (Prelude.Maybe Prelude.Text)
accessMethod_customObjectIdentifier :: (Maybe Text -> f (Maybe Text)) -> AccessMethod -> f AccessMethod
accessMethod_customObjectIdentifier = (AccessMethod -> Maybe Text)
-> (AccessMethod -> Maybe Text -> AccessMethod)
-> Lens AccessMethod AccessMethod (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessMethod' {Maybe Text
customObjectIdentifier :: Maybe Text
$sel:customObjectIdentifier:AccessMethod' :: AccessMethod -> Maybe Text
customObjectIdentifier} -> Maybe Text
customObjectIdentifier) (\s :: AccessMethod
s@AccessMethod' {} Maybe Text
a -> AccessMethod
s {$sel:customObjectIdentifier:AccessMethod' :: Maybe Text
customObjectIdentifier = Maybe Text
a} :: AccessMethod)

instance Core.FromJSON AccessMethod where
  parseJSON :: Value -> Parser AccessMethod
parseJSON =
    String
-> (Object -> Parser AccessMethod) -> Value -> Parser AccessMethod
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AccessMethod"
      ( \Object
x ->
          Maybe AccessMethodType -> Maybe Text -> AccessMethod
AccessMethod'
            (Maybe AccessMethodType -> Maybe Text -> AccessMethod)
-> Parser (Maybe AccessMethodType)
-> Parser (Maybe Text -> AccessMethod)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe AccessMethodType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AccessMethodType")
            Parser (Maybe Text -> AccessMethod)
-> Parser (Maybe Text) -> Parser AccessMethod
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
"CustomObjectIdentifier")
      )

instance Prelude.Hashable AccessMethod

instance Prelude.NFData AccessMethod

instance Core.ToJSON AccessMethod where
  toJSON :: AccessMethod -> Value
toJSON AccessMethod' {Maybe Text
Maybe AccessMethodType
customObjectIdentifier :: Maybe Text
accessMethodType :: Maybe AccessMethodType
$sel:customObjectIdentifier:AccessMethod' :: AccessMethod -> Maybe Text
$sel:accessMethodType:AccessMethod' :: AccessMethod -> Maybe AccessMethodType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AccessMethodType" Text -> AccessMethodType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (AccessMethodType -> Pair) -> Maybe AccessMethodType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AccessMethodType
accessMethodType,
            (Text
"CustomObjectIdentifier" 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
customObjectIdentifier
          ]
      )