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

import Amazonka.AccessAnalyzer.Types.Position
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 span in a policy. The span consists of a start position (inclusive)
-- and end position (exclusive).
--
-- /See:/ 'newSpan' smart constructor.
data Span = Span'
  { -- | The start position of the span (inclusive).
    Span -> Position
start :: Position,
    -- | The end position of the span (exclusive).
    Span -> Position
end :: Position
  }
  deriving (Span -> Span -> Bool
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]
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
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. 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:
--
-- 'start', 'span_start' - The start position of the span (inclusive).
--
-- 'end', 'span_end' - The end position of the span (exclusive).
newSpan ::
  -- | 'start'
  Position ->
  -- | 'end'
  Position ->
  Span
newSpan :: Position -> Position -> Span
newSpan Position
pStart_ Position
pEnd_ =
  Span' {$sel:start:Span' :: Position
start = Position
pStart_, $sel:end:Span' :: Position
end = Position
pEnd_}

-- | The start position of the span (inclusive).
span_start :: Lens.Lens' Span Position
span_start :: Lens' Span Position
span_start = 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)

-- | The end position of the span (exclusive).
span_end :: Lens.Lens' Span Position
span_end :: Lens' Span Position
span_end = 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)

instance Data.FromJSON Span where
  parseJSON :: Value -> Parser Span
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Span"
      ( \Object
x ->
          Position -> Position -> Span
Span'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"start")
            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
"end")
      )

instance Prelude.Hashable Span where
  hashWithSalt :: Int -> Span -> Int
hashWithSalt Int
_salt Span' {Position
end :: Position
start :: Position
$sel:end:Span' :: Span -> Position
$sel:start:Span' :: Span -> Position
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Position
start
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Position
end

instance Prelude.NFData Span where
  rnf :: Span -> ()
rnf Span' {Position
end :: Position
start :: Position
$sel:end:Span' :: Span -> Position
$sel:start:Span' :: Span -> Position
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Position
start seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Position
end