{-# 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.EBS.Types.Block
-- 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.EBS.Types.Block where

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

-- | A block of data in an Amazon Elastic Block Store snapshot.
--
-- /See:/ 'newBlock' smart constructor.
data Block = Block'
  { -- | The block index.
    Block -> Maybe Natural
blockIndex :: Prelude.Maybe Prelude.Natural,
    -- | The block token for the block index.
    Block -> Maybe Text
blockToken :: Prelude.Maybe Prelude.Text
  }
  deriving (Block -> Block -> Bool
(Block -> Block -> Bool) -> (Block -> Block -> Bool) -> Eq Block
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Block -> Block -> Bool
$c/= :: Block -> Block -> Bool
== :: Block -> Block -> Bool
$c== :: Block -> Block -> Bool
Prelude.Eq, ReadPrec [Block]
ReadPrec Block
Int -> ReadS Block
ReadS [Block]
(Int -> ReadS Block)
-> ReadS [Block]
-> ReadPrec Block
-> ReadPrec [Block]
-> Read Block
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Block]
$creadListPrec :: ReadPrec [Block]
readPrec :: ReadPrec Block
$creadPrec :: ReadPrec Block
readList :: ReadS [Block]
$creadList :: ReadS [Block]
readsPrec :: Int -> ReadS Block
$creadsPrec :: Int -> ReadS Block
Prelude.Read, Int -> Block -> ShowS
[Block] -> ShowS
Block -> String
(Int -> Block -> ShowS)
-> (Block -> String) -> ([Block] -> ShowS) -> Show Block
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Block] -> ShowS
$cshowList :: [Block] -> ShowS
show :: Block -> String
$cshow :: Block -> String
showsPrec :: Int -> Block -> ShowS
$cshowsPrec :: Int -> Block -> ShowS
Prelude.Show, (forall x. Block -> Rep Block x)
-> (forall x. Rep Block x -> Block) -> Generic Block
forall x. Rep Block x -> Block
forall x. Block -> Rep Block x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Block x -> Block
$cfrom :: forall x. Block -> Rep Block x
Prelude.Generic)

-- |
-- Create a value of 'Block' 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:
--
-- 'blockIndex', 'block_blockIndex' - The block index.
--
-- 'blockToken', 'block_blockToken' - The block token for the block index.
newBlock ::
  Block
newBlock :: Block
newBlock =
  Block' :: Maybe Natural -> Maybe Text -> Block
Block'
    { $sel:blockIndex:Block' :: Maybe Natural
blockIndex = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:blockToken:Block' :: Maybe Text
blockToken = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The block index.
block_blockIndex :: Lens.Lens' Block (Prelude.Maybe Prelude.Natural)
block_blockIndex :: (Maybe Natural -> f (Maybe Natural)) -> Block -> f Block
block_blockIndex = (Block -> Maybe Natural)
-> (Block -> Maybe Natural -> Block)
-> Lens Block Block (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Block' {Maybe Natural
blockIndex :: Maybe Natural
$sel:blockIndex:Block' :: Block -> Maybe Natural
blockIndex} -> Maybe Natural
blockIndex) (\s :: Block
s@Block' {} Maybe Natural
a -> Block
s {$sel:blockIndex:Block' :: Maybe Natural
blockIndex = Maybe Natural
a} :: Block)

-- | The block token for the block index.
block_blockToken :: Lens.Lens' Block (Prelude.Maybe Prelude.Text)
block_blockToken :: (Maybe Text -> f (Maybe Text)) -> Block -> f Block
block_blockToken = (Block -> Maybe Text)
-> (Block -> Maybe Text -> Block)
-> Lens Block Block (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Block' {Maybe Text
blockToken :: Maybe Text
$sel:blockToken:Block' :: Block -> Maybe Text
blockToken} -> Maybe Text
blockToken) (\s :: Block
s@Block' {} Maybe Text
a -> Block
s {$sel:blockToken:Block' :: Maybe Text
blockToken = Maybe Text
a} :: Block)

instance Core.FromJSON Block where
  parseJSON :: Value -> Parser Block
parseJSON =
    String -> (Object -> Parser Block) -> Value -> Parser Block
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Block"
      ( \Object
x ->
          Maybe Natural -> Maybe Text -> Block
Block'
            (Maybe Natural -> Maybe Text -> Block)
-> Parser (Maybe Natural) -> Parser (Maybe Text -> Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"BlockIndex")
            Parser (Maybe Text -> Block) -> Parser (Maybe Text) -> Parser Block
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
"BlockToken")
      )

instance Prelude.Hashable Block

instance Prelude.NFData Block