{-# 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.AlternateKey
-- 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.AlternateKey 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

-- | Defines an alternate key. This value is optional. A legacy data set
-- might not have any alternate key defined but if those alternate keys
-- definitions exist, provide them, as some applications will make use of
-- them.
--
-- /See:/ 'newAlternateKey' smart constructor.
data AlternateKey = AlternateKey'
  { -- | Indicates whether the alternate key values are supposed to be unique for
    -- the given data set.
    AlternateKey -> Maybe Bool
allowDuplicates :: Prelude.Maybe Prelude.Bool,
    -- | The name of the alternate key.
    AlternateKey -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | A strictly positive integer value representing the length of the
    -- alternate key.
    AlternateKey -> Int
length :: Prelude.Int,
    -- | A positive integer value representing the offset to mark the start of
    -- the alternate key part in the record byte array.
    AlternateKey -> Int
offset :: Prelude.Int
  }
  deriving (AlternateKey -> AlternateKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AlternateKey -> AlternateKey -> Bool
$c/= :: AlternateKey -> AlternateKey -> Bool
== :: AlternateKey -> AlternateKey -> Bool
$c== :: AlternateKey -> AlternateKey -> Bool
Prelude.Eq, ReadPrec [AlternateKey]
ReadPrec AlternateKey
Int -> ReadS AlternateKey
ReadS [AlternateKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AlternateKey]
$creadListPrec :: ReadPrec [AlternateKey]
readPrec :: ReadPrec AlternateKey
$creadPrec :: ReadPrec AlternateKey
readList :: ReadS [AlternateKey]
$creadList :: ReadS [AlternateKey]
readsPrec :: Int -> ReadS AlternateKey
$creadsPrec :: Int -> ReadS AlternateKey
Prelude.Read, Int -> AlternateKey -> ShowS
[AlternateKey] -> ShowS
AlternateKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AlternateKey] -> ShowS
$cshowList :: [AlternateKey] -> ShowS
show :: AlternateKey -> String
$cshow :: AlternateKey -> String
showsPrec :: Int -> AlternateKey -> ShowS
$cshowsPrec :: Int -> AlternateKey -> ShowS
Prelude.Show, forall x. Rep AlternateKey x -> AlternateKey
forall x. AlternateKey -> Rep AlternateKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AlternateKey x -> AlternateKey
$cfrom :: forall x. AlternateKey -> Rep AlternateKey x
Prelude.Generic)

-- |
-- Create a value of 'AlternateKey' 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:
--
-- 'allowDuplicates', 'alternateKey_allowDuplicates' - Indicates whether the alternate key values are supposed to be unique for
-- the given data set.
--
-- 'name', 'alternateKey_name' - The name of the alternate key.
--
-- 'length', 'alternateKey_length' - A strictly positive integer value representing the length of the
-- alternate key.
--
-- 'offset', 'alternateKey_offset' - A positive integer value representing the offset to mark the start of
-- the alternate key part in the record byte array.
newAlternateKey ::
  -- | 'length'
  Prelude.Int ->
  -- | 'offset'
  Prelude.Int ->
  AlternateKey
newAlternateKey :: Int -> Int -> AlternateKey
newAlternateKey Int
pLength_ Int
pOffset_ =
  AlternateKey'
    { $sel:allowDuplicates:AlternateKey' :: Maybe Bool
allowDuplicates = forall a. Maybe a
Prelude.Nothing,
      $sel:name:AlternateKey' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:length:AlternateKey' :: Int
length = Int
pLength_,
      $sel:offset:AlternateKey' :: Int
offset = Int
pOffset_
    }

-- | Indicates whether the alternate key values are supposed to be unique for
-- the given data set.
alternateKey_allowDuplicates :: Lens.Lens' AlternateKey (Prelude.Maybe Prelude.Bool)
alternateKey_allowDuplicates :: Lens' AlternateKey (Maybe Bool)
alternateKey_allowDuplicates = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AlternateKey' {Maybe Bool
allowDuplicates :: Maybe Bool
$sel:allowDuplicates:AlternateKey' :: AlternateKey -> Maybe Bool
allowDuplicates} -> Maybe Bool
allowDuplicates) (\s :: AlternateKey
s@AlternateKey' {} Maybe Bool
a -> AlternateKey
s {$sel:allowDuplicates:AlternateKey' :: Maybe Bool
allowDuplicates = Maybe Bool
a} :: AlternateKey)

-- | The name of the alternate key.
alternateKey_name :: Lens.Lens' AlternateKey (Prelude.Maybe Prelude.Text)
alternateKey_name :: Lens' AlternateKey (Maybe Text)
alternateKey_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AlternateKey' {Maybe Text
name :: Maybe Text
$sel:name:AlternateKey' :: AlternateKey -> Maybe Text
name} -> Maybe Text
name) (\s :: AlternateKey
s@AlternateKey' {} Maybe Text
a -> AlternateKey
s {$sel:name:AlternateKey' :: Maybe Text
name = Maybe Text
a} :: AlternateKey)

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

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

instance Data.FromJSON AlternateKey where
  parseJSON :: Value -> Parser AlternateKey
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AlternateKey"
      ( \Object
x ->
          Maybe Bool -> Maybe Text -> Int -> Int -> AlternateKey
AlternateKey'
            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
"allowDuplicates")
            forall (f :: * -> *) a b. Applicative f => 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 AlternateKey where
  hashWithSalt :: Int -> AlternateKey -> Int
hashWithSalt Int
_salt AlternateKey' {Int
Maybe Bool
Maybe Text
offset :: Int
length :: Int
name :: Maybe Text
allowDuplicates :: Maybe Bool
$sel:offset:AlternateKey' :: AlternateKey -> Int
$sel:length:AlternateKey' :: AlternateKey -> Int
$sel:name:AlternateKey' :: AlternateKey -> Maybe Text
$sel:allowDuplicates:AlternateKey' :: AlternateKey -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
allowDuplicates
      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 AlternateKey where
  rnf :: AlternateKey -> ()
rnf AlternateKey' {Int
Maybe Bool
Maybe Text
offset :: Int
length :: Int
name :: Maybe Text
allowDuplicates :: Maybe Bool
$sel:offset:AlternateKey' :: AlternateKey -> Int
$sel:length:AlternateKey' :: AlternateKey -> Int
$sel:name:AlternateKey' :: AlternateKey -> Maybe Text
$sel:allowDuplicates:AlternateKey' :: AlternateKey -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
allowDuplicates
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 AlternateKey where
  toJSON :: AlternateKey -> Value
toJSON AlternateKey' {Int
Maybe Bool
Maybe Text
offset :: Int
length :: Int
name :: Maybe Text
allowDuplicates :: Maybe Bool
$sel:offset:AlternateKey' :: AlternateKey -> Int
$sel:length:AlternateKey' :: AlternateKey -> Int
$sel:name:AlternateKey' :: AlternateKey -> Maybe Text
$sel:allowDuplicates:AlternateKey' :: AlternateKey -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"allowDuplicates" 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 Bool
allowDuplicates,
            (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)
          ]
      )