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

import Amazonka.AccessAnalyzer.Types.Substring
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

-- | A single element in a path through the JSON representation of a policy.
--
-- /See:/ 'newPathElement' smart constructor.
data PathElement = PathElement'
  { -- | Refers to an index in a JSON array.
    PathElement -> Maybe Int
index :: Prelude.Maybe Prelude.Int,
    -- | Refers to a key in a JSON object.
    PathElement -> Maybe Text
key :: Prelude.Maybe Prelude.Text,
    -- | Refers to a substring of a literal string in a JSON object.
    PathElement -> Maybe Substring
substring :: Prelude.Maybe Substring,
    -- | Refers to the value associated with a given key in a JSON object.
    PathElement -> Maybe Text
value :: Prelude.Maybe Prelude.Text
  }
  deriving (PathElement -> PathElement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PathElement -> PathElement -> Bool
$c/= :: PathElement -> PathElement -> Bool
== :: PathElement -> PathElement -> Bool
$c== :: PathElement -> PathElement -> Bool
Prelude.Eq, ReadPrec [PathElement]
ReadPrec PathElement
Int -> ReadS PathElement
ReadS [PathElement]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PathElement]
$creadListPrec :: ReadPrec [PathElement]
readPrec :: ReadPrec PathElement
$creadPrec :: ReadPrec PathElement
readList :: ReadS [PathElement]
$creadList :: ReadS [PathElement]
readsPrec :: Int -> ReadS PathElement
$creadsPrec :: Int -> ReadS PathElement
Prelude.Read, Int -> PathElement -> ShowS
[PathElement] -> ShowS
PathElement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PathElement] -> ShowS
$cshowList :: [PathElement] -> ShowS
show :: PathElement -> String
$cshow :: PathElement -> String
showsPrec :: Int -> PathElement -> ShowS
$cshowsPrec :: Int -> PathElement -> ShowS
Prelude.Show, forall x. Rep PathElement x -> PathElement
forall x. PathElement -> Rep PathElement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PathElement x -> PathElement
$cfrom :: forall x. PathElement -> Rep PathElement x
Prelude.Generic)

-- |
-- Create a value of 'PathElement' 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:
--
-- 'index', 'pathElement_index' - Refers to an index in a JSON array.
--
-- 'key', 'pathElement_key' - Refers to a key in a JSON object.
--
-- 'substring', 'pathElement_substring' - Refers to a substring of a literal string in a JSON object.
--
-- 'value', 'pathElement_value' - Refers to the value associated with a given key in a JSON object.
newPathElement ::
  PathElement
newPathElement :: PathElement
newPathElement =
  PathElement'
    { $sel:index:PathElement' :: Maybe Int
index = forall a. Maybe a
Prelude.Nothing,
      $sel:key:PathElement' :: Maybe Text
key = forall a. Maybe a
Prelude.Nothing,
      $sel:substring:PathElement' :: Maybe Substring
substring = forall a. Maybe a
Prelude.Nothing,
      $sel:value:PathElement' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing
    }

-- | Refers to an index in a JSON array.
pathElement_index :: Lens.Lens' PathElement (Prelude.Maybe Prelude.Int)
pathElement_index :: Lens' PathElement (Maybe Int)
pathElement_index = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PathElement' {Maybe Int
index :: Maybe Int
$sel:index:PathElement' :: PathElement -> Maybe Int
index} -> Maybe Int
index) (\s :: PathElement
s@PathElement' {} Maybe Int
a -> PathElement
s {$sel:index:PathElement' :: Maybe Int
index = Maybe Int
a} :: PathElement)

-- | Refers to a key in a JSON object.
pathElement_key :: Lens.Lens' PathElement (Prelude.Maybe Prelude.Text)
pathElement_key :: Lens' PathElement (Maybe Text)
pathElement_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PathElement' {Maybe Text
key :: Maybe Text
$sel:key:PathElement' :: PathElement -> Maybe Text
key} -> Maybe Text
key) (\s :: PathElement
s@PathElement' {} Maybe Text
a -> PathElement
s {$sel:key:PathElement' :: Maybe Text
key = Maybe Text
a} :: PathElement)

-- | Refers to a substring of a literal string in a JSON object.
pathElement_substring :: Lens.Lens' PathElement (Prelude.Maybe Substring)
pathElement_substring :: Lens' PathElement (Maybe Substring)
pathElement_substring = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PathElement' {Maybe Substring
substring :: Maybe Substring
$sel:substring:PathElement' :: PathElement -> Maybe Substring
substring} -> Maybe Substring
substring) (\s :: PathElement
s@PathElement' {} Maybe Substring
a -> PathElement
s {$sel:substring:PathElement' :: Maybe Substring
substring = Maybe Substring
a} :: PathElement)

-- | Refers to the value associated with a given key in a JSON object.
pathElement_value :: Lens.Lens' PathElement (Prelude.Maybe Prelude.Text)
pathElement_value :: Lens' PathElement (Maybe Text)
pathElement_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PathElement' {Maybe Text
value :: Maybe Text
$sel:value:PathElement' :: PathElement -> Maybe Text
value} -> Maybe Text
value) (\s :: PathElement
s@PathElement' {} Maybe Text
a -> PathElement
s {$sel:value:PathElement' :: Maybe Text
value = Maybe Text
a} :: PathElement)

instance Data.FromJSON PathElement where
  parseJSON :: Value -> Parser PathElement
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PathElement"
      ( \Object
x ->
          Maybe Int
-> Maybe Text -> Maybe Substring -> Maybe Text -> PathElement
PathElement'
            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
"index")
            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
"key")
            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
"substring")
            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
"value")
      )

instance Prelude.Hashable PathElement where
  hashWithSalt :: Int -> PathElement -> Int
hashWithSalt Int
_salt PathElement' {Maybe Int
Maybe Text
Maybe Substring
value :: Maybe Text
substring :: Maybe Substring
key :: Maybe Text
index :: Maybe Int
$sel:value:PathElement' :: PathElement -> Maybe Text
$sel:substring:PathElement' :: PathElement -> Maybe Substring
$sel:key:PathElement' :: PathElement -> Maybe Text
$sel:index:PathElement' :: PathElement -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
index
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Substring
substring
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value

instance Prelude.NFData PathElement where
  rnf :: PathElement -> ()
rnf PathElement' {Maybe Int
Maybe Text
Maybe Substring
value :: Maybe Text
substring :: Maybe Substring
key :: Maybe Text
index :: Maybe Int
$sel:value:PathElement' :: PathElement -> Maybe Text
$sel:substring:PathElement' :: PathElement -> Maybe Substring
$sel:key:PathElement' :: PathElement -> Maybe Text
$sel:index:PathElement' :: PathElement -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
index
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
key
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Substring
substring
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value