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

import Amazonka.AccessAnalyzer.Types.Substring
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 the value associated with a given key in a JSON object.
    PathElement -> Maybe Text
value :: 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 a key in a JSON object.
    PathElement -> Maybe Text
key :: Prelude.Maybe Prelude.Text,
    -- | Refers to an index in a JSON array.
    PathElement -> Maybe Int
index :: Prelude.Maybe Prelude.Int
  }
  deriving (PathElement -> PathElement -> Bool
(PathElement -> PathElement -> Bool)
-> (PathElement -> PathElement -> Bool) -> Eq PathElement
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]
(Int -> ReadS PathElement)
-> ReadS [PathElement]
-> ReadPrec PathElement
-> ReadPrec [PathElement]
-> Read 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
(Int -> PathElement -> ShowS)
-> (PathElement -> String)
-> ([PathElement] -> ShowS)
-> Show PathElement
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. PathElement -> Rep PathElement x)
-> (forall x. Rep PathElement x -> PathElement)
-> Generic PathElement
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:
--
-- 'value', 'pathElement_value' - Refers to the value associated with a given key in a JSON object.
--
-- 'substring', 'pathElement_substring' - Refers to a substring of a literal string in a JSON object.
--
-- 'key', 'pathElement_key' - Refers to a key in a JSON object.
--
-- 'index', 'pathElement_index' - Refers to an index in a JSON array.
newPathElement ::
  PathElement
newPathElement :: PathElement
newPathElement =
  PathElement' :: Maybe Text
-> Maybe Substring -> Maybe Text -> Maybe Int -> PathElement
PathElement'
    { $sel:value:PathElement' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:substring:PathElement' :: Maybe Substring
substring = Maybe Substring
forall a. Maybe a
Prelude.Nothing,
      $sel:key:PathElement' :: Maybe Text
key = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:index:PathElement' :: Maybe Int
index = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | Refers to the value associated with a given key in a JSON object.
pathElement_value :: Lens.Lens' PathElement (Prelude.Maybe Prelude.Text)
pathElement_value :: (Maybe Text -> f (Maybe Text)) -> PathElement -> f PathElement
pathElement_value = (PathElement -> Maybe Text)
-> (PathElement -> Maybe Text -> PathElement)
-> Lens PathElement PathElement (Maybe Text) (Maybe Text)
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)

-- | Refers to a substring of a literal string in a JSON object.
pathElement_substring :: Lens.Lens' PathElement (Prelude.Maybe Substring)
pathElement_substring :: (Maybe Substring -> f (Maybe Substring))
-> PathElement -> f PathElement
pathElement_substring = (PathElement -> Maybe Substring)
-> (PathElement -> Maybe Substring -> PathElement)
-> Lens PathElement PathElement (Maybe Substring) (Maybe 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 a key in a JSON object.
pathElement_key :: Lens.Lens' PathElement (Prelude.Maybe Prelude.Text)
pathElement_key :: (Maybe Text -> f (Maybe Text)) -> PathElement -> f PathElement
pathElement_key = (PathElement -> Maybe Text)
-> (PathElement -> Maybe Text -> PathElement)
-> Lens PathElement PathElement (Maybe Text) (Maybe Text)
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 an index in a JSON array.
pathElement_index :: Lens.Lens' PathElement (Prelude.Maybe Prelude.Int)
pathElement_index :: (Maybe Int -> f (Maybe Int)) -> PathElement -> f PathElement
pathElement_index = (PathElement -> Maybe Int)
-> (PathElement -> Maybe Int -> PathElement)
-> Lens PathElement PathElement (Maybe Int) (Maybe Int)
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)

instance Core.FromJSON PathElement where
  parseJSON :: Value -> Parser PathElement
parseJSON =
    String
-> (Object -> Parser PathElement) -> Value -> Parser PathElement
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PathElement"
      ( \Object
x ->
          Maybe Text
-> Maybe Substring -> Maybe Text -> Maybe Int -> PathElement
PathElement'
            (Maybe Text
 -> Maybe Substring -> Maybe Text -> Maybe Int -> PathElement)
-> Parser (Maybe Text)
-> Parser
     (Maybe Substring -> Maybe Text -> Maybe Int -> PathElement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"value")
            Parser (Maybe Substring -> Maybe Text -> Maybe Int -> PathElement)
-> Parser (Maybe Substring)
-> Parser (Maybe Text -> Maybe Int -> PathElement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Substring)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"substring")
            Parser (Maybe Text -> Maybe Int -> PathElement)
-> Parser (Maybe Text) -> Parser (Maybe Int -> PathElement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"key")
            Parser (Maybe Int -> PathElement)
-> Parser (Maybe Int) -> Parser PathElement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"index")
      )

instance Prelude.Hashable PathElement

instance Prelude.NFData PathElement