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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 length of the substring.
    Substring -> Int
length :: Prelude.Int,
    -- | The start index of the substring, starting from 0.
    Substring -> Int
start :: Prelude.Int
  }
  deriving (Substring -> Substring -> Bool
(Substring -> Substring -> Bool)
-> (Substring -> Substring -> Bool) -> Eq Substring
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]
(Int -> ReadS Substring)
-> ReadS [Substring]
-> ReadPrec Substring
-> ReadPrec [Substring]
-> Read 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
(Int -> Substring -> ShowS)
-> (Substring -> String)
-> ([Substring] -> ShowS)
-> Show Substring
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. Substring -> Rep Substring x)
-> (forall x. Rep Substring x -> Substring) -> Generic Substring
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:
--
-- 'length', 'substring_length' - The length of the substring.
--
-- 'start', 'substring_start' - The start index of the substring, starting from 0.
newSubstring ::
  -- | 'length'
  Prelude.Int ->
  -- | 'start'
  Prelude.Int ->
  Substring
newSubstring :: Int -> Int -> Substring
newSubstring Int
pLength_ Int
pStart_ =
  Substring' :: Int -> Int -> Substring
Substring' {$sel:length:Substring' :: Int
length = Int
pLength_, $sel:start:Substring' :: Int
start = Int
pStart_}

-- | The length of the substring.
substring_length :: Lens.Lens' Substring Prelude.Int
substring_length :: (Int -> f Int) -> Substring -> f Substring
substring_length = (Substring -> Int)
-> (Substring -> Int -> Substring)
-> Lens Substring Substring Int Int
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)

-- | The start index of the substring, starting from 0.
substring_start :: Lens.Lens' Substring Prelude.Int
substring_start :: (Int -> f Int) -> Substring -> f Substring
substring_start = (Substring -> Int)
-> (Substring -> Int -> Substring)
-> Lens Substring Substring Int Int
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)

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

instance Prelude.Hashable Substring

instance Prelude.NFData Substring