{-# 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.AccessDescription
-- 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.AccessDescription where

import Amazonka.CertificateManagerPCA.Types.AccessMethod
import Amazonka.CertificateManagerPCA.Types.GeneralName
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Provides access information used by the @authorityInfoAccess@ and
-- @subjectInfoAccess@ extensions described in
-- <https://tools.ietf.org/html/rfc5280 RFC 5280>.
--
-- /See:/ 'newAccessDescription' smart constructor.
data AccessDescription = AccessDescription'
  { -- | The type and format of @AccessDescription@ information.
    AccessDescription -> AccessMethod
accessMethod :: AccessMethod,
    -- | The location of @AccessDescription@ information.
    AccessDescription -> GeneralName
accessLocation :: GeneralName
  }
  deriving (AccessDescription -> AccessDescription -> Bool
(AccessDescription -> AccessDescription -> Bool)
-> (AccessDescription -> AccessDescription -> Bool)
-> Eq AccessDescription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccessDescription -> AccessDescription -> Bool
$c/= :: AccessDescription -> AccessDescription -> Bool
== :: AccessDescription -> AccessDescription -> Bool
$c== :: AccessDescription -> AccessDescription -> Bool
Prelude.Eq, ReadPrec [AccessDescription]
ReadPrec AccessDescription
Int -> ReadS AccessDescription
ReadS [AccessDescription]
(Int -> ReadS AccessDescription)
-> ReadS [AccessDescription]
-> ReadPrec AccessDescription
-> ReadPrec [AccessDescription]
-> Read AccessDescription
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AccessDescription]
$creadListPrec :: ReadPrec [AccessDescription]
readPrec :: ReadPrec AccessDescription
$creadPrec :: ReadPrec AccessDescription
readList :: ReadS [AccessDescription]
$creadList :: ReadS [AccessDescription]
readsPrec :: Int -> ReadS AccessDescription
$creadsPrec :: Int -> ReadS AccessDescription
Prelude.Read, Int -> AccessDescription -> ShowS
[AccessDescription] -> ShowS
AccessDescription -> String
(Int -> AccessDescription -> ShowS)
-> (AccessDescription -> String)
-> ([AccessDescription] -> ShowS)
-> Show AccessDescription
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccessDescription] -> ShowS
$cshowList :: [AccessDescription] -> ShowS
show :: AccessDescription -> String
$cshow :: AccessDescription -> String
showsPrec :: Int -> AccessDescription -> ShowS
$cshowsPrec :: Int -> AccessDescription -> ShowS
Prelude.Show, (forall x. AccessDescription -> Rep AccessDescription x)
-> (forall x. Rep AccessDescription x -> AccessDescription)
-> Generic AccessDescription
forall x. Rep AccessDescription x -> AccessDescription
forall x. AccessDescription -> Rep AccessDescription x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AccessDescription x -> AccessDescription
$cfrom :: forall x. AccessDescription -> Rep AccessDescription x
Prelude.Generic)

-- |
-- Create a value of 'AccessDescription' 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:
--
-- 'accessMethod', 'accessDescription_accessMethod' - The type and format of @AccessDescription@ information.
--
-- 'accessLocation', 'accessDescription_accessLocation' - The location of @AccessDescription@ information.
newAccessDescription ::
  -- | 'accessMethod'
  AccessMethod ->
  -- | 'accessLocation'
  GeneralName ->
  AccessDescription
newAccessDescription :: AccessMethod -> GeneralName -> AccessDescription
newAccessDescription AccessMethod
pAccessMethod_ GeneralName
pAccessLocation_ =
  AccessDescription' :: AccessMethod -> GeneralName -> AccessDescription
AccessDescription'
    { $sel:accessMethod:AccessDescription' :: AccessMethod
accessMethod = AccessMethod
pAccessMethod_,
      $sel:accessLocation:AccessDescription' :: GeneralName
accessLocation = GeneralName
pAccessLocation_
    }

-- | The type and format of @AccessDescription@ information.
accessDescription_accessMethod :: Lens.Lens' AccessDescription AccessMethod
accessDescription_accessMethod :: (AccessMethod -> f AccessMethod)
-> AccessDescription -> f AccessDescription
accessDescription_accessMethod = (AccessDescription -> AccessMethod)
-> (AccessDescription -> AccessMethod -> AccessDescription)
-> Lens
     AccessDescription AccessDescription AccessMethod AccessMethod
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessDescription' {AccessMethod
accessMethod :: AccessMethod
$sel:accessMethod:AccessDescription' :: AccessDescription -> AccessMethod
accessMethod} -> AccessMethod
accessMethod) (\s :: AccessDescription
s@AccessDescription' {} AccessMethod
a -> AccessDescription
s {$sel:accessMethod:AccessDescription' :: AccessMethod
accessMethod = AccessMethod
a} :: AccessDescription)

-- | The location of @AccessDescription@ information.
accessDescription_accessLocation :: Lens.Lens' AccessDescription GeneralName
accessDescription_accessLocation :: (GeneralName -> f GeneralName)
-> AccessDescription -> f AccessDescription
accessDescription_accessLocation = (AccessDescription -> GeneralName)
-> (AccessDescription -> GeneralName -> AccessDescription)
-> Lens AccessDescription AccessDescription GeneralName GeneralName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessDescription' {GeneralName
accessLocation :: GeneralName
$sel:accessLocation:AccessDescription' :: AccessDescription -> GeneralName
accessLocation} -> GeneralName
accessLocation) (\s :: AccessDescription
s@AccessDescription' {} GeneralName
a -> AccessDescription
s {$sel:accessLocation:AccessDescription' :: GeneralName
accessLocation = GeneralName
a} :: AccessDescription)

instance Core.FromJSON AccessDescription where
  parseJSON :: Value -> Parser AccessDescription
parseJSON =
    String
-> (Object -> Parser AccessDescription)
-> Value
-> Parser AccessDescription
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AccessDescription"
      ( \Object
x ->
          AccessMethod -> GeneralName -> AccessDescription
AccessDescription'
            (AccessMethod -> GeneralName -> AccessDescription)
-> Parser AccessMethod -> Parser (GeneralName -> AccessDescription)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser AccessMethod
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AccessMethod")
            Parser (GeneralName -> AccessDescription)
-> Parser GeneralName -> Parser AccessDescription
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser GeneralName
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AccessLocation")
      )

instance Prelude.Hashable AccessDescription

instance Prelude.NFData AccessDescription

instance Core.ToJSON AccessDescription where
  toJSON :: AccessDescription -> Value
toJSON AccessDescription' {AccessMethod
GeneralName
accessLocation :: GeneralName
accessMethod :: AccessMethod
$sel:accessLocation:AccessDescription' :: AccessDescription -> GeneralName
$sel:accessMethod:AccessDescription' :: AccessDescription -> AccessMethod
..} =
    [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
"AccessMethod" Text -> AccessMethod -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AccessMethod
accessMethod),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"AccessLocation" Text -> GeneralName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= GeneralName
accessLocation)
          ]
      )