{-# 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.AccessAnalyzer.Types.FindingSource
-- 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.AccessAnalyzer.Types.FindingSource where

import Amazonka.AccessAnalyzer.Types.FindingSourceDetail
import Amazonka.AccessAnalyzer.Types.FindingSourceType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The source of the finding. This indicates how the access that generated
-- the finding is granted. It is populated for Amazon S3 bucket findings.
--
-- /See:/ 'newFindingSource' smart constructor.
data FindingSource = FindingSource'
  { -- | Includes details about how the access that generated the finding is
    -- granted. This is populated for Amazon S3 bucket findings.
    FindingSource -> Maybe FindingSourceDetail
detail :: Prelude.Maybe FindingSourceDetail,
    -- | Indicates the type of access that generated the finding.
    FindingSource -> FindingSourceType
type' :: FindingSourceType
  }
  deriving (FindingSource -> FindingSource -> Bool
(FindingSource -> FindingSource -> Bool)
-> (FindingSource -> FindingSource -> Bool) -> Eq FindingSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FindingSource -> FindingSource -> Bool
$c/= :: FindingSource -> FindingSource -> Bool
== :: FindingSource -> FindingSource -> Bool
$c== :: FindingSource -> FindingSource -> Bool
Prelude.Eq, ReadPrec [FindingSource]
ReadPrec FindingSource
Int -> ReadS FindingSource
ReadS [FindingSource]
(Int -> ReadS FindingSource)
-> ReadS [FindingSource]
-> ReadPrec FindingSource
-> ReadPrec [FindingSource]
-> Read FindingSource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FindingSource]
$creadListPrec :: ReadPrec [FindingSource]
readPrec :: ReadPrec FindingSource
$creadPrec :: ReadPrec FindingSource
readList :: ReadS [FindingSource]
$creadList :: ReadS [FindingSource]
readsPrec :: Int -> ReadS FindingSource
$creadsPrec :: Int -> ReadS FindingSource
Prelude.Read, Int -> FindingSource -> ShowS
[FindingSource] -> ShowS
FindingSource -> String
(Int -> FindingSource -> ShowS)
-> (FindingSource -> String)
-> ([FindingSource] -> ShowS)
-> Show FindingSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FindingSource] -> ShowS
$cshowList :: [FindingSource] -> ShowS
show :: FindingSource -> String
$cshow :: FindingSource -> String
showsPrec :: Int -> FindingSource -> ShowS
$cshowsPrec :: Int -> FindingSource -> ShowS
Prelude.Show, (forall x. FindingSource -> Rep FindingSource x)
-> (forall x. Rep FindingSource x -> FindingSource)
-> Generic FindingSource
forall x. Rep FindingSource x -> FindingSource
forall x. FindingSource -> Rep FindingSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FindingSource x -> FindingSource
$cfrom :: forall x. FindingSource -> Rep FindingSource x
Prelude.Generic)

-- |
-- Create a value of 'FindingSource' 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:
--
-- 'detail', 'findingSource_detail' - Includes details about how the access that generated the finding is
-- granted. This is populated for Amazon S3 bucket findings.
--
-- 'type'', 'findingSource_type' - Indicates the type of access that generated the finding.
newFindingSource ::
  -- | 'type''
  FindingSourceType ->
  FindingSource
newFindingSource :: FindingSourceType -> FindingSource
newFindingSource FindingSourceType
pType_ =
  FindingSource' :: Maybe FindingSourceDetail -> FindingSourceType -> FindingSource
FindingSource'
    { $sel:detail:FindingSource' :: Maybe FindingSourceDetail
detail = Maybe FindingSourceDetail
forall a. Maybe a
Prelude.Nothing,
      $sel:type':FindingSource' :: FindingSourceType
type' = FindingSourceType
pType_
    }

-- | Includes details about how the access that generated the finding is
-- granted. This is populated for Amazon S3 bucket findings.
findingSource_detail :: Lens.Lens' FindingSource (Prelude.Maybe FindingSourceDetail)
findingSource_detail :: (Maybe FindingSourceDetail -> f (Maybe FindingSourceDetail))
-> FindingSource -> f FindingSource
findingSource_detail = (FindingSource -> Maybe FindingSourceDetail)
-> (FindingSource -> Maybe FindingSourceDetail -> FindingSource)
-> Lens
     FindingSource
     FindingSource
     (Maybe FindingSourceDetail)
     (Maybe FindingSourceDetail)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FindingSource' {Maybe FindingSourceDetail
detail :: Maybe FindingSourceDetail
$sel:detail:FindingSource' :: FindingSource -> Maybe FindingSourceDetail
detail} -> Maybe FindingSourceDetail
detail) (\s :: FindingSource
s@FindingSource' {} Maybe FindingSourceDetail
a -> FindingSource
s {$sel:detail:FindingSource' :: Maybe FindingSourceDetail
detail = Maybe FindingSourceDetail
a} :: FindingSource)

-- | Indicates the type of access that generated the finding.
findingSource_type :: Lens.Lens' FindingSource FindingSourceType
findingSource_type :: (FindingSourceType -> f FindingSourceType)
-> FindingSource -> f FindingSource
findingSource_type = (FindingSource -> FindingSourceType)
-> (FindingSource -> FindingSourceType -> FindingSource)
-> Lens
     FindingSource FindingSource FindingSourceType FindingSourceType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FindingSource' {FindingSourceType
type' :: FindingSourceType
$sel:type':FindingSource' :: FindingSource -> FindingSourceType
type'} -> FindingSourceType
type') (\s :: FindingSource
s@FindingSource' {} FindingSourceType
a -> FindingSource
s {$sel:type':FindingSource' :: FindingSourceType
type' = FindingSourceType
a} :: FindingSource)

instance Core.FromJSON FindingSource where
  parseJSON :: Value -> Parser FindingSource
parseJSON =
    String
-> (Object -> Parser FindingSource)
-> Value
-> Parser FindingSource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FindingSource"
      ( \Object
x ->
          Maybe FindingSourceDetail -> FindingSourceType -> FindingSource
FindingSource'
            (Maybe FindingSourceDetail -> FindingSourceType -> FindingSource)
-> Parser (Maybe FindingSourceDetail)
-> Parser (FindingSourceType -> FindingSource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe FindingSourceDetail)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"detail") Parser (FindingSourceType -> FindingSource)
-> Parser FindingSourceType -> Parser FindingSource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser FindingSourceType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
      )

instance Prelude.Hashable FindingSource

instance Prelude.NFData FindingSource