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

import Amazonka.AccessAnalyzer.Types.PathElement
import Amazonka.AccessAnalyzer.Types.Span
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 location in a policy that is represented as a path through the JSON
-- representation and a corresponding span.
--
-- /See:/ 'newLocation' smart constructor.
data Location = Location'
  { -- | A path in a policy, represented as a sequence of path elements.
    Location -> [PathElement]
path :: [PathElement],
    -- | A span in a policy.
    Location -> Span
span :: Span
  }
  deriving (Location -> Location -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Location -> Location -> Bool
$c/= :: Location -> Location -> Bool
== :: Location -> Location -> Bool
$c== :: Location -> Location -> Bool
Prelude.Eq, ReadPrec [Location]
ReadPrec Location
Int -> ReadS Location
ReadS [Location]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Location]
$creadListPrec :: ReadPrec [Location]
readPrec :: ReadPrec Location
$creadPrec :: ReadPrec Location
readList :: ReadS [Location]
$creadList :: ReadS [Location]
readsPrec :: Int -> ReadS Location
$creadsPrec :: Int -> ReadS Location
Prelude.Read, Int -> Location -> ShowS
[Location] -> ShowS
Location -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Location] -> ShowS
$cshowList :: [Location] -> ShowS
show :: Location -> String
$cshow :: Location -> String
showsPrec :: Int -> Location -> ShowS
$cshowsPrec :: Int -> Location -> ShowS
Prelude.Show, forall x. Rep Location x -> Location
forall x. Location -> Rep Location x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Location x -> Location
$cfrom :: forall x. Location -> Rep Location x
Prelude.Generic)

-- |
-- Create a value of 'Location' 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:
--
-- 'path', 'location_path' - A path in a policy, represented as a sequence of path elements.
--
-- 'span', 'location_span' - A span in a policy.
newLocation ::
  -- | 'span'
  Span ->
  Location
newLocation :: Span -> Location
newLocation Span
pSpan_ =
  Location' {$sel:path:Location' :: [PathElement]
path = forall a. Monoid a => a
Prelude.mempty, $sel:span:Location' :: Span
span = Span
pSpan_}

-- | A path in a policy, represented as a sequence of path elements.
location_path :: Lens.Lens' Location [PathElement]
location_path :: Lens' Location [PathElement]
location_path = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Location' {[PathElement]
path :: [PathElement]
$sel:path:Location' :: Location -> [PathElement]
path} -> [PathElement]
path) (\s :: Location
s@Location' {} [PathElement]
a -> Location
s {$sel:path:Location' :: [PathElement]
path = [PathElement]
a} :: Location) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A span in a policy.
location_span :: Lens.Lens' Location Span
location_span :: Lens' Location Span
location_span = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Location' {Span
span :: Span
$sel:span:Location' :: Location -> Span
span} -> Span
span) (\s :: Location
s@Location' {} Span
a -> Location
s {$sel:span:Location' :: Span
span = Span
a} :: Location)

instance Data.FromJSON Location where
  parseJSON :: Value -> Parser Location
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Location"
      ( \Object
x ->
          [PathElement] -> Span -> Location
Location'
            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
"path" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"span")
      )

instance Prelude.Hashable Location where
  hashWithSalt :: Int -> Location -> Int
hashWithSalt Int
_salt Location' {[PathElement]
Span
span :: Span
path :: [PathElement]
$sel:span:Location' :: Location -> Span
$sel:path:Location' :: Location -> [PathElement]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [PathElement]
path
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Span
span

instance Prelude.NFData Location where
  rnf :: Location -> ()
rnf Location' {[PathElement]
Span
span :: Span
path :: [PathElement]
$sel:span:Location' :: Location -> Span
$sel:path:Location' :: Location -> [PathElement]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf [PathElement]
path seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Span
span