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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Defines a custom ASN.1 X.400 @GeneralName@ using an object identifier
-- (OID) and value. 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)>.
--
-- /See:/ 'newOtherName' smart constructor.
data OtherName = OtherName'
  { -- | Specifies an OID.
    OtherName -> Text
typeId :: Prelude.Text,
    -- | Specifies an OID value.
    OtherName -> Text
value :: Prelude.Text
  }
  deriving (OtherName -> OtherName -> Bool
(OtherName -> OtherName -> Bool)
-> (OtherName -> OtherName -> Bool) -> Eq OtherName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OtherName -> OtherName -> Bool
$c/= :: OtherName -> OtherName -> Bool
== :: OtherName -> OtherName -> Bool
$c== :: OtherName -> OtherName -> Bool
Prelude.Eq, ReadPrec [OtherName]
ReadPrec OtherName
Int -> ReadS OtherName
ReadS [OtherName]
(Int -> ReadS OtherName)
-> ReadS [OtherName]
-> ReadPrec OtherName
-> ReadPrec [OtherName]
-> Read OtherName
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OtherName]
$creadListPrec :: ReadPrec [OtherName]
readPrec :: ReadPrec OtherName
$creadPrec :: ReadPrec OtherName
readList :: ReadS [OtherName]
$creadList :: ReadS [OtherName]
readsPrec :: Int -> ReadS OtherName
$creadsPrec :: Int -> ReadS OtherName
Prelude.Read, Int -> OtherName -> ShowS
[OtherName] -> ShowS
OtherName -> String
(Int -> OtherName -> ShowS)
-> (OtherName -> String)
-> ([OtherName] -> ShowS)
-> Show OtherName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OtherName] -> ShowS
$cshowList :: [OtherName] -> ShowS
show :: OtherName -> String
$cshow :: OtherName -> String
showsPrec :: Int -> OtherName -> ShowS
$cshowsPrec :: Int -> OtherName -> ShowS
Prelude.Show, (forall x. OtherName -> Rep OtherName x)
-> (forall x. Rep OtherName x -> OtherName) -> Generic OtherName
forall x. Rep OtherName x -> OtherName
forall x. OtherName -> Rep OtherName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OtherName x -> OtherName
$cfrom :: forall x. OtherName -> Rep OtherName x
Prelude.Generic)

-- |
-- Create a value of 'OtherName' 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:
--
-- 'typeId', 'otherName_typeId' - Specifies an OID.
--
-- 'value', 'otherName_value' - Specifies an OID value.
newOtherName ::
  -- | 'typeId'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  OtherName
newOtherName :: Text -> Text -> OtherName
newOtherName Text
pTypeId_ Text
pValue_ =
  OtherName' :: Text -> Text -> OtherName
OtherName' {$sel:typeId:OtherName' :: Text
typeId = Text
pTypeId_, $sel:value:OtherName' :: Text
value = Text
pValue_}

-- | Specifies an OID.
otherName_typeId :: Lens.Lens' OtherName Prelude.Text
otherName_typeId :: (Text -> f Text) -> OtherName -> f OtherName
otherName_typeId = (OtherName -> Text)
-> (OtherName -> Text -> OtherName)
-> Lens OtherName OtherName Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OtherName' {Text
typeId :: Text
$sel:typeId:OtherName' :: OtherName -> Text
typeId} -> Text
typeId) (\s :: OtherName
s@OtherName' {} Text
a -> OtherName
s {$sel:typeId:OtherName' :: Text
typeId = Text
a} :: OtherName)

-- | Specifies an OID value.
otherName_value :: Lens.Lens' OtherName Prelude.Text
otherName_value :: (Text -> f Text) -> OtherName -> f OtherName
otherName_value = (OtherName -> Text)
-> (OtherName -> Text -> OtherName)
-> Lens OtherName OtherName Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OtherName' {Text
value :: Text
$sel:value:OtherName' :: OtherName -> Text
value} -> Text
value) (\s :: OtherName
s@OtherName' {} Text
a -> OtherName
s {$sel:value:OtherName' :: Text
value = Text
a} :: OtherName)

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

instance Prelude.Hashable OtherName

instance Prelude.NFData OtherName

instance Core.ToJSON OtherName where
  toJSON :: OtherName -> Value
toJSON OtherName' {Text
value :: Text
typeId :: Text
$sel:value:OtherName' :: OtherName -> Text
$sel:typeId:OtherName' :: OtherName -> Text
..} =
    [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
"TypeId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
typeId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value)
          ]
      )