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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A position in a policy.
--
-- /See:/ 'newPosition' smart constructor.
data Position = Position'
  { -- | The column of the position, starting from 0.
    Position -> Int
column :: Prelude.Int,
    -- | The line of the position, starting from 1.
    Position -> Int
line :: Prelude.Int,
    -- | The offset within the policy that corresponds to the position, starting
    -- from 0.
    Position -> Int
offset :: Prelude.Int
  }
  deriving (Position -> Position -> Bool
(Position -> Position -> Bool)
-> (Position -> Position -> Bool) -> Eq Position
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Position -> Position -> Bool
$c/= :: Position -> Position -> Bool
== :: Position -> Position -> Bool
$c== :: Position -> Position -> Bool
Prelude.Eq, ReadPrec [Position]
ReadPrec Position
Int -> ReadS Position
ReadS [Position]
(Int -> ReadS Position)
-> ReadS [Position]
-> ReadPrec Position
-> ReadPrec [Position]
-> Read Position
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Position]
$creadListPrec :: ReadPrec [Position]
readPrec :: ReadPrec Position
$creadPrec :: ReadPrec Position
readList :: ReadS [Position]
$creadList :: ReadS [Position]
readsPrec :: Int -> ReadS Position
$creadsPrec :: Int -> ReadS Position
Prelude.Read, Int -> Position -> ShowS
[Position] -> ShowS
Position -> String
(Int -> Position -> ShowS)
-> (Position -> String) -> ([Position] -> ShowS) -> Show Position
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Position] -> ShowS
$cshowList :: [Position] -> ShowS
show :: Position -> String
$cshow :: Position -> String
showsPrec :: Int -> Position -> ShowS
$cshowsPrec :: Int -> Position -> ShowS
Prelude.Show, (forall x. Position -> Rep Position x)
-> (forall x. Rep Position x -> Position) -> Generic Position
forall x. Rep Position x -> Position
forall x. Position -> Rep Position x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Position x -> Position
$cfrom :: forall x. Position -> Rep Position x
Prelude.Generic)

-- |
-- Create a value of 'Position' 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:
--
-- 'column', 'position_column' - The column of the position, starting from 0.
--
-- 'line', 'position_line' - The line of the position, starting from 1.
--
-- 'offset', 'position_offset' - The offset within the policy that corresponds to the position, starting
-- from 0.
newPosition ::
  -- | 'column'
  Prelude.Int ->
  -- | 'line'
  Prelude.Int ->
  -- | 'offset'
  Prelude.Int ->
  Position
newPosition :: Int -> Int -> Int -> Position
newPosition Int
pColumn_ Int
pLine_ Int
pOffset_ =
  Position' :: Int -> Int -> Int -> Position
Position'
    { $sel:column:Position' :: Int
column = Int
pColumn_,
      $sel:line:Position' :: Int
line = Int
pLine_,
      $sel:offset:Position' :: Int
offset = Int
pOffset_
    }

-- | The column of the position, starting from 0.
position_column :: Lens.Lens' Position Prelude.Int
position_column :: (Int -> f Int) -> Position -> f Position
position_column = (Position -> Int)
-> (Position -> Int -> Position) -> Lens Position Position Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Position' {Int
column :: Int
$sel:column:Position' :: Position -> Int
column} -> Int
column) (\s :: Position
s@Position' {} Int
a -> Position
s {$sel:column:Position' :: Int
column = Int
a} :: Position)

-- | The line of the position, starting from 1.
position_line :: Lens.Lens' Position Prelude.Int
position_line :: (Int -> f Int) -> Position -> f Position
position_line = (Position -> Int)
-> (Position -> Int -> Position) -> Lens Position Position Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Position' {Int
line :: Int
$sel:line:Position' :: Position -> Int
line} -> Int
line) (\s :: Position
s@Position' {} Int
a -> Position
s {$sel:line:Position' :: Int
line = Int
a} :: Position)

-- | The offset within the policy that corresponds to the position, starting
-- from 0.
position_offset :: Lens.Lens' Position Prelude.Int
position_offset :: (Int -> f Int) -> Position -> f Position
position_offset = (Position -> Int)
-> (Position -> Int -> Position) -> Lens Position Position Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Position' {Int
offset :: Int
$sel:offset:Position' :: Position -> Int
offset} -> Int
offset) (\s :: Position
s@Position' {} Int
a -> Position
s {$sel:offset:Position' :: Int
offset = Int
a} :: Position)

instance Core.FromJSON Position where
  parseJSON :: Value -> Parser Position
parseJSON =
    String -> (Object -> Parser Position) -> Value -> Parser Position
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Position"
      ( \Object
x ->
          Int -> Int -> Int -> Position
Position'
            (Int -> Int -> Int -> Position)
-> Parser Int -> Parser (Int -> Int -> Position)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"column")
            Parser (Int -> Int -> Position)
-> Parser Int -> Parser (Int -> Position)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"line")
            Parser (Int -> Position) -> Parser Int -> Parser Position
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"offset")
      )

instance Prelude.Hashable Position

instance Prelude.NFData Position