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

-- | Contains a numeric value in decimal format.
--
-- /See:/ 'newDecimalNumber' smart constructor.
data DecimalNumber = DecimalNumber'
  { -- | The unscaled numeric value.
    DecimalNumber -> Base64
unscaledValue :: Data.Base64,
    -- | The scale that determines where the decimal point falls in the unscaled
    -- value.
    DecimalNumber -> Int
scale :: Prelude.Int
  }
  deriving (DecimalNumber -> DecimalNumber -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DecimalNumber -> DecimalNumber -> Bool
$c/= :: DecimalNumber -> DecimalNumber -> Bool
== :: DecimalNumber -> DecimalNumber -> Bool
$c== :: DecimalNumber -> DecimalNumber -> Bool
Prelude.Eq, ReadPrec [DecimalNumber]
ReadPrec DecimalNumber
Int -> ReadS DecimalNumber
ReadS [DecimalNumber]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DecimalNumber]
$creadListPrec :: ReadPrec [DecimalNumber]
readPrec :: ReadPrec DecimalNumber
$creadPrec :: ReadPrec DecimalNumber
readList :: ReadS [DecimalNumber]
$creadList :: ReadS [DecimalNumber]
readsPrec :: Int -> ReadS DecimalNumber
$creadsPrec :: Int -> ReadS DecimalNumber
Prelude.Read, Int -> DecimalNumber -> ShowS
[DecimalNumber] -> ShowS
DecimalNumber -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DecimalNumber] -> ShowS
$cshowList :: [DecimalNumber] -> ShowS
show :: DecimalNumber -> String
$cshow :: DecimalNumber -> String
showsPrec :: Int -> DecimalNumber -> ShowS
$cshowsPrec :: Int -> DecimalNumber -> ShowS
Prelude.Show, forall x. Rep DecimalNumber x -> DecimalNumber
forall x. DecimalNumber -> Rep DecimalNumber x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DecimalNumber x -> DecimalNumber
$cfrom :: forall x. DecimalNumber -> Rep DecimalNumber x
Prelude.Generic)

-- |
-- Create a value of 'DecimalNumber' 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:
--
-- 'unscaledValue', 'decimalNumber_unscaledValue' - The unscaled numeric value.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
--
-- 'scale', 'decimalNumber_scale' - The scale that determines where the decimal point falls in the unscaled
-- value.
newDecimalNumber ::
  -- | 'unscaledValue'
  Prelude.ByteString ->
  -- | 'scale'
  Prelude.Int ->
  DecimalNumber
newDecimalNumber :: ByteString -> Int -> DecimalNumber
newDecimalNumber ByteString
pUnscaledValue_ Int
pScale_ =
  DecimalNumber'
    { $sel:unscaledValue:DecimalNumber' :: Base64
unscaledValue =
        Iso' Base64 ByteString
Data._Base64 forall t b. AReview t b -> b -> t
Lens.# ByteString
pUnscaledValue_,
      $sel:scale:DecimalNumber' :: Int
scale = Int
pScale_
    }

-- | The unscaled numeric value.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
decimalNumber_unscaledValue :: Lens.Lens' DecimalNumber Prelude.ByteString
decimalNumber_unscaledValue :: Lens' DecimalNumber ByteString
decimalNumber_unscaledValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DecimalNumber' {Base64
unscaledValue :: Base64
$sel:unscaledValue:DecimalNumber' :: DecimalNumber -> Base64
unscaledValue} -> Base64
unscaledValue) (\s :: DecimalNumber
s@DecimalNumber' {} Base64
a -> DecimalNumber
s {$sel:unscaledValue:DecimalNumber' :: Base64
unscaledValue = Base64
a} :: DecimalNumber) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Iso' Base64 ByteString
Data._Base64

-- | The scale that determines where the decimal point falls in the unscaled
-- value.
decimalNumber_scale :: Lens.Lens' DecimalNumber Prelude.Int
decimalNumber_scale :: Lens' DecimalNumber Int
decimalNumber_scale = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DecimalNumber' {Int
scale :: Int
$sel:scale:DecimalNumber' :: DecimalNumber -> Int
scale} -> Int
scale) (\s :: DecimalNumber
s@DecimalNumber' {} Int
a -> DecimalNumber
s {$sel:scale:DecimalNumber' :: Int
scale = Int
a} :: DecimalNumber)

instance Data.FromJSON DecimalNumber where
  parseJSON :: Value -> Parser DecimalNumber
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DecimalNumber"
      ( \Object
x ->
          Base64 -> Int -> DecimalNumber
DecimalNumber'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"UnscaledValue")
            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
"Scale")
      )

instance Prelude.Hashable DecimalNumber where
  hashWithSalt :: Int -> DecimalNumber -> Int
hashWithSalt Int
_salt DecimalNumber' {Int
Base64
scale :: Int
unscaledValue :: Base64
$sel:scale:DecimalNumber' :: DecimalNumber -> Int
$sel:unscaledValue:DecimalNumber' :: DecimalNumber -> Base64
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Base64
unscaledValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
scale

instance Prelude.NFData DecimalNumber where
  rnf :: DecimalNumber -> ()
rnf DecimalNumber' {Int
Base64
scale :: Int
unscaledValue :: Base64
$sel:scale:DecimalNumber' :: DecimalNumber -> Int
$sel:unscaledValue:DecimalNumber' :: DecimalNumber -> Base64
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Base64
unscaledValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
scale

instance Data.ToJSON DecimalNumber where
  toJSON :: DecimalNumber -> Value
toJSON DecimalNumber' {Int
Base64
scale :: Int
unscaledValue :: Base64
$sel:scale:DecimalNumber' :: DecimalNumber -> Int
$sel:unscaledValue:DecimalNumber' :: DecimalNumber -> Base64
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"UnscaledValue" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Base64
unscaledValue),
            forall a. a -> Maybe a
Prelude.Just (Key
"Scale" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Int
scale)
          ]
      )