{-# 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.M2.Types.PrimaryKey
-- 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.M2.Types.PrimaryKey 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

-- | The primary key for a KSDS data set.
--
-- /See:/ 'newPrimaryKey' smart constructor.
data PrimaryKey = PrimaryKey'
  { -- | A name for the Primary Key.
    PrimaryKey -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | A strictly positive integer value representing the length of the primary
    -- key.
    PrimaryKey -> Int
length :: Prelude.Int,
    -- | A positive integer value representing the offset to mark the start of
    -- the primary key in the record byte array.
    PrimaryKey -> Int
offset :: Prelude.Int
  }
  deriving (PrimaryKey -> PrimaryKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrimaryKey -> PrimaryKey -> Bool
$c/= :: PrimaryKey -> PrimaryKey -> Bool
== :: PrimaryKey -> PrimaryKey -> Bool
$c== :: PrimaryKey -> PrimaryKey -> Bool
Prelude.Eq, ReadPrec [PrimaryKey]
ReadPrec PrimaryKey
Int -> ReadS PrimaryKey
ReadS [PrimaryKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PrimaryKey]
$creadListPrec :: ReadPrec [PrimaryKey]
readPrec :: ReadPrec PrimaryKey
$creadPrec :: ReadPrec PrimaryKey
readList :: ReadS [PrimaryKey]
$creadList :: ReadS [PrimaryKey]
readsPrec :: Int -> ReadS PrimaryKey
$creadsPrec :: Int -> ReadS PrimaryKey
Prelude.Read, Int -> PrimaryKey -> ShowS
[PrimaryKey] -> ShowS
PrimaryKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrimaryKey] -> ShowS
$cshowList :: [PrimaryKey] -> ShowS
show :: PrimaryKey -> String
$cshow :: PrimaryKey -> String
showsPrec :: Int -> PrimaryKey -> ShowS
$cshowsPrec :: Int -> PrimaryKey -> ShowS
Prelude.Show, forall x. Rep PrimaryKey x -> PrimaryKey
forall x. PrimaryKey -> Rep PrimaryKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PrimaryKey x -> PrimaryKey
$cfrom :: forall x. PrimaryKey -> Rep PrimaryKey x
Prelude.Generic)

-- |
-- Create a value of 'PrimaryKey' 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:
--
-- 'name', 'primaryKey_name' - A name for the Primary Key.
--
-- 'length', 'primaryKey_length' - A strictly positive integer value representing the length of the primary
-- key.
--
-- 'offset', 'primaryKey_offset' - A positive integer value representing the offset to mark the start of
-- the primary key in the record byte array.
newPrimaryKey ::
  -- | 'length'
  Prelude.Int ->
  -- | 'offset'
  Prelude.Int ->
  PrimaryKey
newPrimaryKey :: Int -> Int -> PrimaryKey
newPrimaryKey Int
pLength_ Int
pOffset_ =
  PrimaryKey'
    { $sel:name:PrimaryKey' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:length:PrimaryKey' :: Int
length = Int
pLength_,
      $sel:offset:PrimaryKey' :: Int
offset = Int
pOffset_
    }

-- | A name for the Primary Key.
primaryKey_name :: Lens.Lens' PrimaryKey (Prelude.Maybe Prelude.Text)
primaryKey_name :: Lens' PrimaryKey (Maybe Text)
primaryKey_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PrimaryKey' {Maybe Text
name :: Maybe Text
$sel:name:PrimaryKey' :: PrimaryKey -> Maybe Text
name} -> Maybe Text
name) (\s :: PrimaryKey
s@PrimaryKey' {} Maybe Text
a -> PrimaryKey
s {$sel:name:PrimaryKey' :: Maybe Text
name = Maybe Text
a} :: PrimaryKey)

-- | A strictly positive integer value representing the length of the primary
-- key.
primaryKey_length :: Lens.Lens' PrimaryKey Prelude.Int
primaryKey_length :: Lens' PrimaryKey Int
primaryKey_length = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PrimaryKey' {Int
length :: Int
$sel:length:PrimaryKey' :: PrimaryKey -> Int
length} -> Int
length) (\s :: PrimaryKey
s@PrimaryKey' {} Int
a -> PrimaryKey
s {$sel:length:PrimaryKey' :: Int
length = Int
a} :: PrimaryKey)

-- | A positive integer value representing the offset to mark the start of
-- the primary key in the record byte array.
primaryKey_offset :: Lens.Lens' PrimaryKey Prelude.Int
primaryKey_offset :: Lens' PrimaryKey Int
primaryKey_offset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PrimaryKey' {Int
offset :: Int
$sel:offset:PrimaryKey' :: PrimaryKey -> Int
offset} -> Int
offset) (\s :: PrimaryKey
s@PrimaryKey' {} Int
a -> PrimaryKey
s {$sel:offset:PrimaryKey' :: Int
offset = Int
a} :: PrimaryKey)

instance Data.FromJSON PrimaryKey where
  parseJSON :: Value -> Parser PrimaryKey
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PrimaryKey"
      ( \Object
x ->
          Maybe Text -> Int -> Int -> PrimaryKey
PrimaryKey'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"name")
            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")
            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
"offset")
      )

instance Prelude.Hashable PrimaryKey where
  hashWithSalt :: Int -> PrimaryKey -> Int
hashWithSalt Int
_salt PrimaryKey' {Int
Maybe Text
offset :: Int
length :: Int
name :: Maybe Text
$sel:offset:PrimaryKey' :: PrimaryKey -> Int
$sel:length:PrimaryKey' :: PrimaryKey -> Int
$sel:name:PrimaryKey' :: PrimaryKey -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
length
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
offset

instance Prelude.NFData PrimaryKey where
  rnf :: PrimaryKey -> ()
rnf PrimaryKey' {Int
Maybe Text
offset :: Int
length :: Int
name :: Maybe Text
$sel:offset:PrimaryKey' :: PrimaryKey -> Int
$sel:length:PrimaryKey' :: PrimaryKey -> Int
$sel:name:PrimaryKey' :: PrimaryKey -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
length
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
offset

instance Data.ToJSON PrimaryKey where
  toJSON :: PrimaryKey -> Value
toJSON PrimaryKey' {Int
Maybe Text
offset :: Int
length :: Int
name :: Maybe Text
$sel:offset:PrimaryKey' :: PrimaryKey -> Int
$sel:length:PrimaryKey' :: PrimaryKey -> Int
$sel:name:PrimaryKey' :: PrimaryKey -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            forall a. a -> Maybe a
Prelude.Just (Key
"length" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Int
length),
            forall a. a -> Maybe a
Prelude.Just (Key
"offset" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Int
offset)
          ]
      )