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

import Amazonka.AccessAnalyzer.Types.PathElement
import Amazonka.AccessAnalyzer.Types.Span
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(Location -> Location -> Bool)
-> (Location -> Location -> Bool) -> Eq Location
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]
(Int -> ReadS Location)
-> ReadS [Location]
-> ReadPrec Location
-> ReadPrec [Location]
-> Read 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
(Int -> Location -> ShowS)
-> (Location -> String) -> ([Location] -> ShowS) -> Show Location
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. Location -> Rep Location x)
-> (forall x. Rep Location x -> Location) -> Generic Location
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' :: [PathElement] -> Span -> Location
Location' {$sel:path:Location' :: [PathElement]
path = [PathElement]
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 :: ([PathElement] -> f [PathElement]) -> Location -> f Location
location_path = (Location -> [PathElement])
-> (Location -> [PathElement] -> Location)
-> Lens Location Location [PathElement] [PathElement]
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) (([PathElement] -> f [PathElement]) -> Location -> f Location)
-> (([PathElement] -> f [PathElement])
    -> [PathElement] -> f [PathElement])
-> ([PathElement] -> f [PathElement])
-> Location
-> f Location
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([PathElement] -> f [PathElement])
-> [PathElement] -> f [PathElement]
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 :: (Span -> f Span) -> Location -> f Location
location_span = (Location -> Span)
-> (Location -> Span -> Location)
-> Lens Location Location Span 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 Core.FromJSON Location where
  parseJSON :: Value -> Parser Location
parseJSON =
    String -> (Object -> Parser Location) -> Value -> Parser Location
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Location"
      ( \Object
x ->
          [PathElement] -> Span -> Location
Location'
            ([PathElement] -> Span -> Location)
-> Parser [PathElement] -> Parser (Span -> Location)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe [PathElement])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"path" Parser (Maybe [PathElement])
-> [PathElement] -> Parser [PathElement]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [PathElement]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Span -> Location) -> Parser Span -> Parser Location
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Span
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"span")
      )

instance Prelude.Hashable Location

instance Prelude.NFData Location