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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 :: Core.Base64,
    -- | The scale that determines where the decimal point falls in the unscaled
    -- value.
    DecimalNumber -> Int
scale :: Prelude.Int
  }
  deriving (DecimalNumber -> DecimalNumber -> Bool
(DecimalNumber -> DecimalNumber -> Bool)
-> (DecimalNumber -> DecimalNumber -> Bool) -> Eq DecimalNumber
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]
(Int -> ReadS DecimalNumber)
-> ReadS [DecimalNumber]
-> ReadPrec DecimalNumber
-> ReadPrec [DecimalNumber]
-> Read 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
(Int -> DecimalNumber -> ShowS)
-> (DecimalNumber -> String)
-> ([DecimalNumber] -> ShowS)
-> Show DecimalNumber
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. DecimalNumber -> Rep DecimalNumber x)
-> (forall x. Rep DecimalNumber x -> DecimalNumber)
-> Generic DecimalNumber
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' :: Base64 -> Int -> DecimalNumber
DecimalNumber'
    { $sel:unscaledValue:DecimalNumber' :: Base64
unscaledValue =
        Tagged ByteString (Identity ByteString)
-> Tagged Base64 (Identity Base64)
Iso' Base64 ByteString
Core._Base64 (Tagged ByteString (Identity ByteString)
 -> Tagged Base64 (Identity Base64))
-> ByteString -> 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 :: (ByteString -> f ByteString) -> DecimalNumber -> f DecimalNumber
decimalNumber_unscaledValue = (DecimalNumber -> Base64)
-> (DecimalNumber -> Base64 -> DecimalNumber)
-> Lens DecimalNumber DecimalNumber Base64 Base64
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) ((Base64 -> f Base64) -> DecimalNumber -> f DecimalNumber)
-> ((ByteString -> f ByteString) -> Base64 -> f Base64)
-> (ByteString -> f ByteString)
-> DecimalNumber
-> f DecimalNumber
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ByteString -> f ByteString) -> Base64 -> f Base64
Iso' Base64 ByteString
Core._Base64

-- | The scale that determines where the decimal point falls in the unscaled
-- value.
decimalNumber_scale :: Lens.Lens' DecimalNumber Prelude.Int
decimalNumber_scale :: (Int -> f Int) -> DecimalNumber -> f DecimalNumber
decimalNumber_scale = (DecimalNumber -> Int)
-> (DecimalNumber -> Int -> DecimalNumber)
-> Lens DecimalNumber DecimalNumber Int Int
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 Core.FromJSON DecimalNumber where
  parseJSON :: Value -> Parser DecimalNumber
parseJSON =
    String
-> (Object -> Parser DecimalNumber)
-> Value
-> Parser DecimalNumber
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DecimalNumber"
      ( \Object
x ->
          Base64 -> Int -> DecimalNumber
DecimalNumber'
            (Base64 -> Int -> DecimalNumber)
-> Parser Base64 -> Parser (Int -> DecimalNumber)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Base64
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"UnscaledValue")
            Parser (Int -> DecimalNumber) -> Parser Int -> Parser DecimalNumber
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Scale")
      )

instance Prelude.Hashable DecimalNumber

instance Prelude.NFData DecimalNumber

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"UnscaledValue" Text -> Base64 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Base64
unscaledValue),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Scale" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
scale)
          ]
      )