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

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 reference to a substring of a literal string in a JSON document.
--
-- /See:/ 'newSubstring' smart constructor.
data Substring = Substring'
  { -- | The start index of the substring, starting from 0.
    Substring -> Int
start :: Prelude.Int,
    -- | The length of the substring.
    Substring -> Int
length :: Prelude.Int
  }
  deriving (Substring -> Substring -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Substring -> Substring -> Bool
$c/= :: Substring -> Substring -> Bool
== :: Substring -> Substring -> Bool
$c== :: Substring -> Substring -> Bool
Prelude.Eq, ReadPrec [Substring]
ReadPrec Substring
Int -> ReadS Substring
ReadS [Substring]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Substring]
$creadListPrec :: ReadPrec [Substring]
readPrec :: ReadPrec Substring
$creadPrec :: ReadPrec Substring
readList :: ReadS [Substring]
$creadList :: ReadS [Substring]
readsPrec :: Int -> ReadS Substring
$creadsPrec :: Int -> ReadS Substring
Prelude.Read, Int -> Substring -> ShowS
[Substring] -> ShowS
Substring -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Substring] -> ShowS
$cshowList :: [Substring] -> ShowS
show :: Substring -> String
$cshow :: Substring -> String
showsPrec :: Int -> Substring -> ShowS
$cshowsPrec :: Int -> Substring -> ShowS
Prelude.Show, forall x. Rep Substring x -> Substring
forall x. Substring -> Rep Substring x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Substring x -> Substring
$cfrom :: forall x. Substring -> Rep Substring x
Prelude.Generic)

-- |
-- Create a value of 'Substring' 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', 'substring_start' - The start index of the substring, starting from 0.
--
-- 'length', 'substring_length' - The length of the substring.
newSubstring ::
  -- | 'start'
  Prelude.Int ->
  -- | 'length'
  Prelude.Int ->
  Substring
newSubstring :: Int -> Int -> Substring
newSubstring Int
pStart_ Int
pLength_ =
  Substring' {$sel:start:Substring' :: Int
start = Int
pStart_, $sel:length:Substring' :: Int
length = Int
pLength_}

-- | The start index of the substring, starting from 0.
substring_start :: Lens.Lens' Substring Prelude.Int
substring_start :: Lens' Substring Int
substring_start = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Substring' {Int
start :: Int
$sel:start:Substring' :: Substring -> Int
start} -> Int
start) (\s :: Substring
s@Substring' {} Int
a -> Substring
s {$sel:start:Substring' :: Int
start = Int
a} :: Substring)

-- | The length of the substring.
substring_length :: Lens.Lens' Substring Prelude.Int
substring_length :: Lens' Substring Int
substring_length = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Substring' {Int
length :: Int
$sel:length:Substring' :: Substring -> Int
length} -> Int
length) (\s :: Substring
s@Substring' {} Int
a -> Substring
s {$sel:length:Substring' :: Int
length = Int
a} :: Substring)

instance Data.FromJSON Substring where
  parseJSON :: Value -> Parser Substring
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Substring"
      ( \Object
x ->
          Int -> Int -> Substring
Substring'
            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
"length")
      )

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

instance Prelude.NFData Substring where
  rnf :: Substring -> ()
rnf Substring' {Int
length :: Int
start :: Int
$sel:length:Substring' :: Substring -> Int
$sel:start:Substring' :: Substring -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
start seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
length