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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(UsageAllocation -> UsageAllocation -> Bool)
-> (UsageAllocation -> UsageAllocation -> Bool)
-> Eq UsageAllocation
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]
(Int -> ReadS UsageAllocation)
-> ReadS [UsageAllocation]
-> ReadPrec UsageAllocation
-> ReadPrec [UsageAllocation]
-> Read 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
(Int -> UsageAllocation -> ShowS)
-> (UsageAllocation -> String)
-> ([UsageAllocation] -> ShowS)
-> Show UsageAllocation
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. UsageAllocation -> Rep UsageAllocation x)
-> (forall x. Rep UsageAllocation x -> UsageAllocation)
-> Generic UsageAllocation
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' :: Maybe (NonEmpty Tag) -> Natural -> UsageAllocation
UsageAllocation'
    { $sel:tags:UsageAllocation' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
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 :: (Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> UsageAllocation -> f UsageAllocation
usageAllocation_tags = (UsageAllocation -> Maybe (NonEmpty Tag))
-> (UsageAllocation -> Maybe (NonEmpty Tag) -> UsageAllocation)
-> Lens
     UsageAllocation
     UsageAllocation
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
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) ((Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
 -> UsageAllocation -> f UsageAllocation)
-> ((Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
    -> Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> (Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> UsageAllocation
-> f UsageAllocation
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag)
-> Iso
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
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 AnIso (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag)
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 :: (Natural -> f Natural) -> UsageAllocation -> f UsageAllocation
usageAllocation_allocatedUsageQuantity = (UsageAllocation -> Natural)
-> (UsageAllocation -> Natural -> UsageAllocation)
-> Lens UsageAllocation UsageAllocation Natural Natural
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 Core.FromJSON UsageAllocation where
  parseJSON :: Value -> Parser UsageAllocation
parseJSON =
    String
-> (Object -> Parser UsageAllocation)
-> Value
-> Parser UsageAllocation
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"UsageAllocation"
      ( \Object
x ->
          Maybe (NonEmpty Tag) -> Natural -> UsageAllocation
UsageAllocation'
            (Maybe (NonEmpty Tag) -> Natural -> UsageAllocation)
-> Parser (Maybe (NonEmpty Tag))
-> Parser (Natural -> UsageAllocation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Tag))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Tags")
            Parser (Natural -> UsageAllocation)
-> Parser Natural -> Parser UsageAllocation
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AllocatedUsageQuantity")
      )

instance Prelude.Hashable UsageAllocation

instance Prelude.NFData UsageAllocation

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Tags" Text -> NonEmpty Tag -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Tag -> Pair) -> Maybe (NonEmpty Tag) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Tag)
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"AllocatedUsageQuantity"
                  Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
allocatedUsageQuantity
              )
          ]
      )