{-# 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.MarketplaceMetering.Types.UsageAllocation
-- 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.MarketplaceMetering.Types.UsageAllocation where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.MarketplaceMetering.Types.Tag
import qualified Amazonka.Prelude as Prelude

-- | Usage allocations allow you to split usage into buckets by tags.
--
-- Each @UsageAllocation@ indicates the usage quantity for a specific set
-- of tags.
--
-- /See:/ 'newUsageAllocation' smart constructor.
data UsageAllocation = UsageAllocation'
  { -- | The set of tags that define the bucket of usage. For the bucket of items
    -- with no tags, this parameter can be left out.
    UsageAllocation -> Maybe (NonEmpty Tag)
tags :: Prelude.Maybe (Prelude.NonEmpty Tag),
    -- | The total quantity allocated to this bucket of usage.
    UsageAllocation -> Natural
allocatedUsageQuantity :: Prelude.Natural
  }
  deriving (UsageAllocation -> UsageAllocation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UsageAllocation -> UsageAllocation -> Bool
$c/= :: UsageAllocation -> UsageAllocation -> Bool
== :: UsageAllocation -> UsageAllocation -> Bool
$c== :: UsageAllocation -> UsageAllocation -> Bool
Prelude.Eq, ReadPrec [UsageAllocation]
ReadPrec UsageAllocation
Int -> ReadS UsageAllocation
ReadS [UsageAllocation]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UsageAllocation]
$creadListPrec :: ReadPrec [UsageAllocation]
readPrec :: ReadPrec UsageAllocation
$creadPrec :: ReadPrec UsageAllocation
readList :: ReadS [UsageAllocation]
$creadList :: ReadS [UsageAllocation]
readsPrec :: Int -> ReadS UsageAllocation
$creadsPrec :: Int -> ReadS UsageAllocation
Prelude.Read, Int -> UsageAllocation -> ShowS
[UsageAllocation] -> ShowS
UsageAllocation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UsageAllocation] -> ShowS
$cshowList :: [UsageAllocation] -> ShowS
show :: UsageAllocation -> String
$cshow :: UsageAllocation -> String
showsPrec :: Int -> UsageAllocation -> ShowS
$cshowsPrec :: Int -> UsageAllocation -> ShowS
Prelude.Show, forall x. Rep UsageAllocation x -> UsageAllocation
forall x. UsageAllocation -> Rep UsageAllocation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UsageAllocation x -> UsageAllocation
$cfrom :: forall x. UsageAllocation -> Rep UsageAllocation x
Prelude.Generic)

-- |
-- Create a value of 'UsageAllocation' 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:
--
-- 'tags', 'usageAllocation_tags' - The set of tags that define the bucket of usage. For the bucket of items
-- with no tags, this parameter can be left out.
--
-- 'allocatedUsageQuantity', 'usageAllocation_allocatedUsageQuantity' - The total quantity allocated to this bucket of usage.
newUsageAllocation ::
  -- | 'allocatedUsageQuantity'
  Prelude.Natural ->
  UsageAllocation
newUsageAllocation :: Natural -> UsageAllocation
newUsageAllocation Natural
pAllocatedUsageQuantity_ =
  UsageAllocation'
    { $sel:tags:UsageAllocation' :: Maybe (NonEmpty Tag)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:allocatedUsageQuantity:UsageAllocation' :: Natural
allocatedUsageQuantity = Natural
pAllocatedUsageQuantity_
    }

-- | The set of tags that define the bucket of usage. For the bucket of items
-- with no tags, this parameter can be left out.
usageAllocation_tags :: Lens.Lens' UsageAllocation (Prelude.Maybe (Prelude.NonEmpty Tag))
usageAllocation_tags :: Lens' UsageAllocation (Maybe (NonEmpty Tag))
usageAllocation_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageAllocation' {Maybe (NonEmpty Tag)
tags :: Maybe (NonEmpty Tag)
$sel:tags:UsageAllocation' :: UsageAllocation -> Maybe (NonEmpty Tag)
tags} -> Maybe (NonEmpty Tag)
tags) (\s :: UsageAllocation
s@UsageAllocation' {} Maybe (NonEmpty Tag)
a -> UsageAllocation
s {$sel:tags:UsageAllocation' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
a} :: UsageAllocation) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The total quantity allocated to this bucket of usage.
usageAllocation_allocatedUsageQuantity :: Lens.Lens' UsageAllocation Prelude.Natural
usageAllocation_allocatedUsageQuantity :: Lens' UsageAllocation Natural
usageAllocation_allocatedUsageQuantity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageAllocation' {Natural
allocatedUsageQuantity :: Natural
$sel:allocatedUsageQuantity:UsageAllocation' :: UsageAllocation -> Natural
allocatedUsageQuantity} -> Natural
allocatedUsageQuantity) (\s :: UsageAllocation
s@UsageAllocation' {} Natural
a -> UsageAllocation
s {$sel:allocatedUsageQuantity:UsageAllocation' :: Natural
allocatedUsageQuantity = Natural
a} :: UsageAllocation)

instance Data.FromJSON UsageAllocation where
  parseJSON :: Value -> Parser UsageAllocation
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"UsageAllocation"
      ( \Object
x ->
          Maybe (NonEmpty Tag) -> Natural -> UsageAllocation
UsageAllocation'
            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
"Tags")
            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
"AllocatedUsageQuantity")
      )

instance Prelude.Hashable UsageAllocation where
  hashWithSalt :: Int -> UsageAllocation -> Int
hashWithSalt Int
_salt UsageAllocation' {Natural
Maybe (NonEmpty Tag)
allocatedUsageQuantity :: Natural
tags :: Maybe (NonEmpty Tag)
$sel:allocatedUsageQuantity:UsageAllocation' :: UsageAllocation -> Natural
$sel:tags:UsageAllocation' :: UsageAllocation -> Maybe (NonEmpty Tag)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Tag)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
allocatedUsageQuantity

instance Prelude.NFData UsageAllocation where
  rnf :: UsageAllocation -> ()
rnf UsageAllocation' {Natural
Maybe (NonEmpty Tag)
allocatedUsageQuantity :: Natural
tags :: Maybe (NonEmpty Tag)
$sel:allocatedUsageQuantity:UsageAllocation' :: UsageAllocation -> Natural
$sel:tags:UsageAllocation' :: UsageAllocation -> Maybe (NonEmpty Tag)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Tag)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
allocatedUsageQuantity

instance Data.ToJSON UsageAllocation where
  toJSON :: UsageAllocation -> Value
toJSON UsageAllocation' {Natural
Maybe (NonEmpty Tag)
allocatedUsageQuantity :: Natural
tags :: Maybe (NonEmpty Tag)
$sel:allocatedUsageQuantity:UsageAllocation' :: UsageAllocation -> Natural
$sel:tags:UsageAllocation' :: UsageAllocation -> Maybe (NonEmpty Tag)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Tags" 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 (NonEmpty Tag)
tags,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"AllocatedUsageQuantity"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
allocatedUsageQuantity
              )
          ]
      )