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

import Amazonka.AccessAnalyzer.Types.Position
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A span in a policy. The span consists of a start position (inclusive)
-- and end position (exclusive).
--
-- /See:/ 'newSpan' smart constructor.
data Span = Span'
  { -- | The end position of the span (exclusive).
    Span -> Position
end :: Position,
    -- | The start position of the span (inclusive).
    Span -> Position
start :: Position
  }
  deriving (Span -> Span -> Bool
(Span -> Span -> Bool) -> (Span -> Span -> Bool) -> Eq Span
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Span -> Span -> Bool
$c/= :: Span -> Span -> Bool
== :: Span -> Span -> Bool
$c== :: Span -> Span -> Bool
Prelude.Eq, ReadPrec [Span]
ReadPrec Span
Int -> ReadS Span
ReadS [Span]
(Int -> ReadS Span)
-> ReadS [Span] -> ReadPrec Span -> ReadPrec [Span] -> Read Span
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Span]
$creadListPrec :: ReadPrec [Span]
readPrec :: ReadPrec Span
$creadPrec :: ReadPrec Span
readList :: ReadS [Span]
$creadList :: ReadS [Span]
readsPrec :: Int -> ReadS Span
$creadsPrec :: Int -> ReadS Span
Prelude.Read, Int -> Span -> ShowS
[Span] -> ShowS
Span -> String
(Int -> Span -> ShowS)
-> (Span -> String) -> ([Span] -> ShowS) -> Show Span
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Span] -> ShowS
$cshowList :: [Span] -> ShowS
show :: Span -> String
$cshow :: Span -> String
showsPrec :: Int -> Span -> ShowS
$cshowsPrec :: Int -> Span -> ShowS
Prelude.Show, (forall x. Span -> Rep Span x)
-> (forall x. Rep Span x -> Span) -> Generic Span
forall x. Rep Span x -> Span
forall x. Span -> Rep Span x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Span x -> Span
$cfrom :: forall x. Span -> Rep Span x
Prelude.Generic)

-- |
-- Create a value of 'Span' 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:
--
-- 'end', 'span_end' - The end position of the span (exclusive).
--
-- 'start', 'span_start' - The start position of the span (inclusive).
newSpan ::
  -- | 'end'
  Position ->
  -- | 'start'
  Position ->
  Span
newSpan :: Position -> Position -> Span
newSpan Position
pEnd_ Position
pStart_ =
  Span' :: Position -> Position -> Span
Span' {$sel:end:Span' :: Position
end = Position
pEnd_, $sel:start:Span' :: Position
start = Position
pStart_}

-- | The end position of the span (exclusive).
span_end :: Lens.Lens' Span Position
span_end :: (Position -> f Position) -> Span -> f Span
span_end = (Span -> Position)
-> (Span -> Position -> Span) -> Lens Span Span Position Position
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Span' {Position
end :: Position
$sel:end:Span' :: Span -> Position
end} -> Position
end) (\s :: Span
s@Span' {} Position
a -> Span
s {$sel:end:Span' :: Position
end = Position
a} :: Span)

-- | The start position of the span (inclusive).
span_start :: Lens.Lens' Span Position
span_start :: (Position -> f Position) -> Span -> f Span
span_start = (Span -> Position)
-> (Span -> Position -> Span) -> Lens Span Span Position Position
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Span' {Position
start :: Position
$sel:start:Span' :: Span -> Position
start} -> Position
start) (\s :: Span
s@Span' {} Position
a -> Span
s {$sel:start:Span' :: Position
start = Position
a} :: Span)

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

instance Prelude.Hashable Span

instance Prelude.NFData Span