{-# 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.Snowball.Types.KeyRange
-- 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.Snowball.Types.KeyRange where

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

-- | Contains a key range. For export jobs, a @S3Resource@ object can have an
-- optional @KeyRange@ value. The length of the range is defined at job
-- creation, and has either an inclusive @BeginMarker@, an inclusive
-- @EndMarker@, or both. Ranges are UTF-8 binary sorted.
--
-- /See:/ 'newKeyRange' smart constructor.
data KeyRange = KeyRange'
  { -- | The key that ends an optional key range for an export job. Ranges are
    -- inclusive and UTF-8 binary sorted.
    KeyRange -> Maybe Text
endMarker :: Prelude.Maybe Prelude.Text,
    -- | The key that starts an optional key range for an export job. Ranges are
    -- inclusive and UTF-8 binary sorted.
    KeyRange -> Maybe Text
beginMarker :: Prelude.Maybe Prelude.Text
  }
  deriving (KeyRange -> KeyRange -> Bool
(KeyRange -> KeyRange -> Bool)
-> (KeyRange -> KeyRange -> Bool) -> Eq KeyRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KeyRange -> KeyRange -> Bool
$c/= :: KeyRange -> KeyRange -> Bool
== :: KeyRange -> KeyRange -> Bool
$c== :: KeyRange -> KeyRange -> Bool
Prelude.Eq, ReadPrec [KeyRange]
ReadPrec KeyRange
Int -> ReadS KeyRange
ReadS [KeyRange]
(Int -> ReadS KeyRange)
-> ReadS [KeyRange]
-> ReadPrec KeyRange
-> ReadPrec [KeyRange]
-> Read KeyRange
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KeyRange]
$creadListPrec :: ReadPrec [KeyRange]
readPrec :: ReadPrec KeyRange
$creadPrec :: ReadPrec KeyRange
readList :: ReadS [KeyRange]
$creadList :: ReadS [KeyRange]
readsPrec :: Int -> ReadS KeyRange
$creadsPrec :: Int -> ReadS KeyRange
Prelude.Read, Int -> KeyRange -> ShowS
[KeyRange] -> ShowS
KeyRange -> String
(Int -> KeyRange -> ShowS)
-> (KeyRange -> String) -> ([KeyRange] -> ShowS) -> Show KeyRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KeyRange] -> ShowS
$cshowList :: [KeyRange] -> ShowS
show :: KeyRange -> String
$cshow :: KeyRange -> String
showsPrec :: Int -> KeyRange -> ShowS
$cshowsPrec :: Int -> KeyRange -> ShowS
Prelude.Show, (forall x. KeyRange -> Rep KeyRange x)
-> (forall x. Rep KeyRange x -> KeyRange) -> Generic KeyRange
forall x. Rep KeyRange x -> KeyRange
forall x. KeyRange -> Rep KeyRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KeyRange x -> KeyRange
$cfrom :: forall x. KeyRange -> Rep KeyRange x
Prelude.Generic)

-- |
-- Create a value of 'KeyRange' 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:
--
-- 'endMarker', 'keyRange_endMarker' - The key that ends an optional key range for an export job. Ranges are
-- inclusive and UTF-8 binary sorted.
--
-- 'beginMarker', 'keyRange_beginMarker' - The key that starts an optional key range for an export job. Ranges are
-- inclusive and UTF-8 binary sorted.
newKeyRange ::
  KeyRange
newKeyRange :: KeyRange
newKeyRange =
  KeyRange' :: Maybe Text -> Maybe Text -> KeyRange
KeyRange'
    { $sel:endMarker:KeyRange' :: Maybe Text
endMarker = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:beginMarker:KeyRange' :: Maybe Text
beginMarker = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The key that ends an optional key range for an export job. Ranges are
-- inclusive and UTF-8 binary sorted.
keyRange_endMarker :: Lens.Lens' KeyRange (Prelude.Maybe Prelude.Text)
keyRange_endMarker :: (Maybe Text -> f (Maybe Text)) -> KeyRange -> f KeyRange
keyRange_endMarker = (KeyRange -> Maybe Text)
-> (KeyRange -> Maybe Text -> KeyRange)
-> Lens KeyRange KeyRange (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyRange' {Maybe Text
endMarker :: Maybe Text
$sel:endMarker:KeyRange' :: KeyRange -> Maybe Text
endMarker} -> Maybe Text
endMarker) (\s :: KeyRange
s@KeyRange' {} Maybe Text
a -> KeyRange
s {$sel:endMarker:KeyRange' :: Maybe Text
endMarker = Maybe Text
a} :: KeyRange)

-- | The key that starts an optional key range for an export job. Ranges are
-- inclusive and UTF-8 binary sorted.
keyRange_beginMarker :: Lens.Lens' KeyRange (Prelude.Maybe Prelude.Text)
keyRange_beginMarker :: (Maybe Text -> f (Maybe Text)) -> KeyRange -> f KeyRange
keyRange_beginMarker = (KeyRange -> Maybe Text)
-> (KeyRange -> Maybe Text -> KeyRange)
-> Lens KeyRange KeyRange (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyRange' {Maybe Text
beginMarker :: Maybe Text
$sel:beginMarker:KeyRange' :: KeyRange -> Maybe Text
beginMarker} -> Maybe Text
beginMarker) (\s :: KeyRange
s@KeyRange' {} Maybe Text
a -> KeyRange
s {$sel:beginMarker:KeyRange' :: Maybe Text
beginMarker = Maybe Text
a} :: KeyRange)

instance Core.FromJSON KeyRange where
  parseJSON :: Value -> Parser KeyRange
parseJSON =
    String -> (Object -> Parser KeyRange) -> Value -> Parser KeyRange
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"KeyRange"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> KeyRange
KeyRange'
            (Maybe Text -> Maybe Text -> KeyRange)
-> Parser (Maybe Text) -> Parser (Maybe Text -> KeyRange)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EndMarker")
            Parser (Maybe Text -> KeyRange)
-> Parser (Maybe Text) -> Parser KeyRange
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"BeginMarker")
      )

instance Prelude.Hashable KeyRange

instance Prelude.NFData KeyRange

instance Core.ToJSON KeyRange where
  toJSON :: KeyRange -> Value
toJSON KeyRange' {Maybe Text
beginMarker :: Maybe Text
endMarker :: Maybe Text
$sel:beginMarker:KeyRange' :: KeyRange -> Maybe Text
$sel:endMarker:KeyRange' :: KeyRange -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EndMarker" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
endMarker,
            (Text
"BeginMarker" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
beginMarker
          ]
      )