{-# 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.Glue.Types.Segment
-- 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.Glue.Types.Segment where

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

-- | Defines a non-overlapping region of a table\'s partitions, allowing
-- multiple requests to be run in parallel.
--
-- /See:/ 'newSegment' smart constructor.
data Segment = Segment'
  { -- | The zero-based index number of the segment. For example, if the total
    -- number of segments is 4, @SegmentNumber@ values range from 0 through 3.
    Segment -> Natural
segmentNumber :: Prelude.Natural,
    -- | The total number of segments.
    Segment -> Natural
totalSegments :: Prelude.Natural
  }
  deriving (Segment -> Segment -> Bool
(Segment -> Segment -> Bool)
-> (Segment -> Segment -> Bool) -> Eq Segment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Segment -> Segment -> Bool
$c/= :: Segment -> Segment -> Bool
== :: Segment -> Segment -> Bool
$c== :: Segment -> Segment -> Bool
Prelude.Eq, ReadPrec [Segment]
ReadPrec Segment
Int -> ReadS Segment
ReadS [Segment]
(Int -> ReadS Segment)
-> ReadS [Segment]
-> ReadPrec Segment
-> ReadPrec [Segment]
-> Read Segment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Segment]
$creadListPrec :: ReadPrec [Segment]
readPrec :: ReadPrec Segment
$creadPrec :: ReadPrec Segment
readList :: ReadS [Segment]
$creadList :: ReadS [Segment]
readsPrec :: Int -> ReadS Segment
$creadsPrec :: Int -> ReadS Segment
Prelude.Read, Int -> Segment -> ShowS
[Segment] -> ShowS
Segment -> String
(Int -> Segment -> ShowS)
-> (Segment -> String) -> ([Segment] -> ShowS) -> Show Segment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Segment] -> ShowS
$cshowList :: [Segment] -> ShowS
show :: Segment -> String
$cshow :: Segment -> String
showsPrec :: Int -> Segment -> ShowS
$cshowsPrec :: Int -> Segment -> ShowS
Prelude.Show, (forall x. Segment -> Rep Segment x)
-> (forall x. Rep Segment x -> Segment) -> Generic Segment
forall x. Rep Segment x -> Segment
forall x. Segment -> Rep Segment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Segment x -> Segment
$cfrom :: forall x. Segment -> Rep Segment x
Prelude.Generic)

-- |
-- Create a value of 'Segment' 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:
--
-- 'segmentNumber', 'segment_segmentNumber' - The zero-based index number of the segment. For example, if the total
-- number of segments is 4, @SegmentNumber@ values range from 0 through 3.
--
-- 'totalSegments', 'segment_totalSegments' - The total number of segments.
newSegment ::
  -- | 'segmentNumber'
  Prelude.Natural ->
  -- | 'totalSegments'
  Prelude.Natural ->
  Segment
newSegment :: Natural -> Natural -> Segment
newSegment Natural
pSegmentNumber_ Natural
pTotalSegments_ =
  Segment' :: Natural -> Natural -> Segment
Segment'
    { $sel:segmentNumber:Segment' :: Natural
segmentNumber = Natural
pSegmentNumber_,
      $sel:totalSegments:Segment' :: Natural
totalSegments = Natural
pTotalSegments_
    }

-- | The zero-based index number of the segment. For example, if the total
-- number of segments is 4, @SegmentNumber@ values range from 0 through 3.
segment_segmentNumber :: Lens.Lens' Segment Prelude.Natural
segment_segmentNumber :: (Natural -> f Natural) -> Segment -> f Segment
segment_segmentNumber = (Segment -> Natural)
-> (Segment -> Natural -> Segment)
-> Lens Segment Segment Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Natural
segmentNumber :: Natural
$sel:segmentNumber:Segment' :: Segment -> Natural
segmentNumber} -> Natural
segmentNumber) (\s :: Segment
s@Segment' {} Natural
a -> Segment
s {$sel:segmentNumber:Segment' :: Natural
segmentNumber = Natural
a} :: Segment)

-- | The total number of segments.
segment_totalSegments :: Lens.Lens' Segment Prelude.Natural
segment_totalSegments :: (Natural -> f Natural) -> Segment -> f Segment
segment_totalSegments = (Segment -> Natural)
-> (Segment -> Natural -> Segment)
-> Lens Segment Segment Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Natural
totalSegments :: Natural
$sel:totalSegments:Segment' :: Segment -> Natural
totalSegments} -> Natural
totalSegments) (\s :: Segment
s@Segment' {} Natural
a -> Segment
s {$sel:totalSegments:Segment' :: Natural
totalSegments = Natural
a} :: Segment)

instance Prelude.Hashable Segment

instance Prelude.NFData Segment

instance Core.ToJSON Segment where
  toJSON :: Segment -> Value
toJSON Segment' {Natural
totalSegments :: Natural
segmentNumber :: Natural
$sel:totalSegments:Segment' :: Segment -> Natural
$sel:segmentNumber:Segment' :: Segment -> Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"SegmentNumber" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
segmentNumber),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"TotalSegments" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
totalSegments)
          ]
      )