{-# 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.RolesAnywhere.Types.Source
-- 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.RolesAnywhere.Types.Source 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
import Amazonka.RolesAnywhere.Types.SourceData
import Amazonka.RolesAnywhere.Types.TrustAnchorType

-- | The trust anchor type and its related certificate data.
--
-- /See:/ 'newSource' smart constructor.
data Source = Source'
  { -- | The data field of the trust anchor depending on its type.
    Source -> Maybe SourceData
sourceData :: Prelude.Maybe SourceData,
    -- | The type of the trust anchor.
    Source -> Maybe TrustAnchorType
sourceType :: Prelude.Maybe TrustAnchorType
  }
  deriving (Source -> Source -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Source -> Source -> Bool
$c/= :: Source -> Source -> Bool
== :: Source -> Source -> Bool
$c== :: Source -> Source -> Bool
Prelude.Eq, ReadPrec [Source]
ReadPrec Source
Int -> ReadS Source
ReadS [Source]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Source]
$creadListPrec :: ReadPrec [Source]
readPrec :: ReadPrec Source
$creadPrec :: ReadPrec Source
readList :: ReadS [Source]
$creadList :: ReadS [Source]
readsPrec :: Int -> ReadS Source
$creadsPrec :: Int -> ReadS Source
Prelude.Read, Int -> Source -> ShowS
[Source] -> ShowS
Source -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Source] -> ShowS
$cshowList :: [Source] -> ShowS
show :: Source -> String
$cshow :: Source -> String
showsPrec :: Int -> Source -> ShowS
$cshowsPrec :: Int -> Source -> ShowS
Prelude.Show, forall x. Rep Source x -> Source
forall x. Source -> Rep Source x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Source x -> Source
$cfrom :: forall x. Source -> Rep Source x
Prelude.Generic)

-- |
-- Create a value of 'Source' 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:
--
-- 'sourceData', 'source_sourceData' - The data field of the trust anchor depending on its type.
--
-- 'sourceType', 'source_sourceType' - The type of the trust anchor.
newSource ::
  Source
newSource :: Source
newSource =
  Source'
    { $sel:sourceData:Source' :: Maybe SourceData
sourceData = forall a. Maybe a
Prelude.Nothing,
      $sel:sourceType:Source' :: Maybe TrustAnchorType
sourceType = forall a. Maybe a
Prelude.Nothing
    }

-- | The data field of the trust anchor depending on its type.
source_sourceData :: Lens.Lens' Source (Prelude.Maybe SourceData)
source_sourceData :: Lens' Source (Maybe SourceData)
source_sourceData = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Source' {Maybe SourceData
sourceData :: Maybe SourceData
$sel:sourceData:Source' :: Source -> Maybe SourceData
sourceData} -> Maybe SourceData
sourceData) (\s :: Source
s@Source' {} Maybe SourceData
a -> Source
s {$sel:sourceData:Source' :: Maybe SourceData
sourceData = Maybe SourceData
a} :: Source)

-- | The type of the trust anchor.
source_sourceType :: Lens.Lens' Source (Prelude.Maybe TrustAnchorType)
source_sourceType :: Lens' Source (Maybe TrustAnchorType)
source_sourceType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Source' {Maybe TrustAnchorType
sourceType :: Maybe TrustAnchorType
$sel:sourceType:Source' :: Source -> Maybe TrustAnchorType
sourceType} -> Maybe TrustAnchorType
sourceType) (\s :: Source
s@Source' {} Maybe TrustAnchorType
a -> Source
s {$sel:sourceType:Source' :: Maybe TrustAnchorType
sourceType = Maybe TrustAnchorType
a} :: Source)

instance Data.FromJSON Source where
  parseJSON :: Value -> Parser Source
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Source"
      ( \Object
x ->
          Maybe SourceData -> Maybe TrustAnchorType -> Source
Source'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"sourceData")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"sourceType")
      )

instance Prelude.Hashable Source where
  hashWithSalt :: Int -> Source -> Int
hashWithSalt Int
_salt Source' {Maybe SourceData
Maybe TrustAnchorType
sourceType :: Maybe TrustAnchorType
sourceData :: Maybe SourceData
$sel:sourceType:Source' :: Source -> Maybe TrustAnchorType
$sel:sourceData:Source' :: Source -> Maybe SourceData
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SourceData
sourceData
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe TrustAnchorType
sourceType

instance Prelude.NFData Source where
  rnf :: Source -> ()
rnf Source' {Maybe SourceData
Maybe TrustAnchorType
sourceType :: Maybe TrustAnchorType
sourceData :: Maybe SourceData
$sel:sourceType:Source' :: Source -> Maybe TrustAnchorType
$sel:sourceData:Source' :: Source -> Maybe SourceData
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe SourceData
sourceData
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe TrustAnchorType
sourceType

instance Data.ToJSON Source where
  toJSON :: Source -> Value
toJSON Source' {Maybe SourceData
Maybe TrustAnchorType
sourceType :: Maybe TrustAnchorType
sourceData :: Maybe SourceData
$sel:sourceType:Source' :: Source -> Maybe TrustAnchorType
$sel:sourceData:Source' :: Source -> Maybe SourceData
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"sourceData" 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 SourceData
sourceData,
            (Key
"sourceType" 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 TrustAnchorType
sourceType
          ]
      )