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

import Amazonka.CertificateManagerPCA.Types.AccessMethod
import Amazonka.CertificateManagerPCA.Types.GeneralName
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

-- | Provides access information used by the @authorityInfoAccess@ and
-- @subjectInfoAccess@ extensions described in
-- <https://datatracker.ietf.org/doc/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
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]
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
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. 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'
    { $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 :: Lens' AccessDescription AccessMethod
accessDescription_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 :: Lens' AccessDescription GeneralName
accessDescription_accessLocation = 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 Data.FromJSON AccessDescription where
  parseJSON :: Value -> Parser AccessDescription
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AccessDescription"
      ( \Object
x ->
          AccessMethod -> GeneralName -> AccessDescription
AccessDescription'
            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
"AccessMethod")
            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
"AccessLocation")
      )

instance Prelude.Hashable AccessDescription where
  hashWithSalt :: Int -> AccessDescription -> Int
hashWithSalt Int
_salt AccessDescription' {AccessMethod
GeneralName
accessLocation :: GeneralName
accessMethod :: AccessMethod
$sel:accessLocation:AccessDescription' :: AccessDescription -> GeneralName
$sel:accessMethod:AccessDescription' :: AccessDescription -> AccessMethod
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AccessMethod
accessMethod
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` GeneralName
accessLocation

instance Prelude.NFData AccessDescription where
  rnf :: AccessDescription -> ()
rnf AccessDescription' {AccessMethod
GeneralName
accessLocation :: GeneralName
accessMethod :: AccessMethod
$sel:accessLocation:AccessDescription' :: AccessDescription -> GeneralName
$sel:accessMethod:AccessDescription' :: AccessDescription -> AccessMethod
..} =
    forall a. NFData a => a -> ()
Prelude.rnf AccessMethod
accessMethod
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf GeneralName
accessLocation

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"AccessMethod" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= AccessMethod
accessMethod),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"AccessLocation" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= GeneralName
accessLocation)
          ]
      )