{-# 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.CostExplorer.Types.CostCategorySplitChargeRule
-- 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.CostExplorer.Types.CostCategorySplitChargeRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import Amazonka.CostExplorer.Types.CostCategorySplitChargeMethod
import Amazonka.CostExplorer.Types.CostCategorySplitChargeRuleParameter
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Use the split charge rule to split the cost of one Cost Category value
-- across several other target values.
--
-- /See:/ 'newCostCategorySplitChargeRule' smart constructor.
data CostCategorySplitChargeRule = CostCategorySplitChargeRule'
  { -- | The parameters for a split charge method. This is only required for the
    -- @FIXED@ method.
    CostCategorySplitChargeRule
-> Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
parameters :: Prelude.Maybe (Prelude.NonEmpty CostCategorySplitChargeRuleParameter),
    -- | The Cost Category value that you want to split. That value can\'t be
    -- used as a source or a target in other split charge rules. To indicate
    -- uncategorized costs, you can use an empty string as the source.
    CostCategorySplitChargeRule -> Text
source :: Prelude.Text,
    -- | The Cost Category values that you want to split costs across. These
    -- values can\'t be used as a source in other split charge rules.
    CostCategorySplitChargeRule -> NonEmpty Text
targets :: Prelude.NonEmpty Prelude.Text,
    -- | The method that\'s used to define how to split your source costs across
    -- your targets.
    --
    -- @Proportional@ - Allocates charges across your targets based on the
    -- proportional weighted cost of each target.
    --
    -- @Fixed@ - Allocates charges across your targets based on your defined
    -- allocation percentage.
    --
    -- >@Even@ - Allocates costs evenly across all targets.
    CostCategorySplitChargeRule -> CostCategorySplitChargeMethod
method :: CostCategorySplitChargeMethod
  }
  deriving (CostCategorySplitChargeRule -> CostCategorySplitChargeRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CostCategorySplitChargeRule -> CostCategorySplitChargeRule -> Bool
$c/= :: CostCategorySplitChargeRule -> CostCategorySplitChargeRule -> Bool
== :: CostCategorySplitChargeRule -> CostCategorySplitChargeRule -> Bool
$c== :: CostCategorySplitChargeRule -> CostCategorySplitChargeRule -> Bool
Prelude.Eq, ReadPrec [CostCategorySplitChargeRule]
ReadPrec CostCategorySplitChargeRule
Int -> ReadS CostCategorySplitChargeRule
ReadS [CostCategorySplitChargeRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CostCategorySplitChargeRule]
$creadListPrec :: ReadPrec [CostCategorySplitChargeRule]
readPrec :: ReadPrec CostCategorySplitChargeRule
$creadPrec :: ReadPrec CostCategorySplitChargeRule
readList :: ReadS [CostCategorySplitChargeRule]
$creadList :: ReadS [CostCategorySplitChargeRule]
readsPrec :: Int -> ReadS CostCategorySplitChargeRule
$creadsPrec :: Int -> ReadS CostCategorySplitChargeRule
Prelude.Read, Int -> CostCategorySplitChargeRule -> ShowS
[CostCategorySplitChargeRule] -> ShowS
CostCategorySplitChargeRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CostCategorySplitChargeRule] -> ShowS
$cshowList :: [CostCategorySplitChargeRule] -> ShowS
show :: CostCategorySplitChargeRule -> String
$cshow :: CostCategorySplitChargeRule -> String
showsPrec :: Int -> CostCategorySplitChargeRule -> ShowS
$cshowsPrec :: Int -> CostCategorySplitChargeRule -> ShowS
Prelude.Show, forall x.
Rep CostCategorySplitChargeRule x -> CostCategorySplitChargeRule
forall x.
CostCategorySplitChargeRule -> Rep CostCategorySplitChargeRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CostCategorySplitChargeRule x -> CostCategorySplitChargeRule
$cfrom :: forall x.
CostCategorySplitChargeRule -> Rep CostCategorySplitChargeRule x
Prelude.Generic)

-- |
-- Create a value of 'CostCategorySplitChargeRule' 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:
--
-- 'parameters', 'costCategorySplitChargeRule_parameters' - The parameters for a split charge method. This is only required for the
-- @FIXED@ method.
--
-- 'source', 'costCategorySplitChargeRule_source' - The Cost Category value that you want to split. That value can\'t be
-- used as a source or a target in other split charge rules. To indicate
-- uncategorized costs, you can use an empty string as the source.
--
-- 'targets', 'costCategorySplitChargeRule_targets' - The Cost Category values that you want to split costs across. These
-- values can\'t be used as a source in other split charge rules.
--
-- 'method', 'costCategorySplitChargeRule_method' - The method that\'s used to define how to split your source costs across
-- your targets.
--
-- @Proportional@ - Allocates charges across your targets based on the
-- proportional weighted cost of each target.
--
-- @Fixed@ - Allocates charges across your targets based on your defined
-- allocation percentage.
--
-- >@Even@ - Allocates costs evenly across all targets.
newCostCategorySplitChargeRule ::
  -- | 'source'
  Prelude.Text ->
  -- | 'targets'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'method'
  CostCategorySplitChargeMethod ->
  CostCategorySplitChargeRule
newCostCategorySplitChargeRule :: Text
-> NonEmpty Text
-> CostCategorySplitChargeMethod
-> CostCategorySplitChargeRule
newCostCategorySplitChargeRule
  Text
pSource_
  NonEmpty Text
pTargets_
  CostCategorySplitChargeMethod
pMethod_ =
    CostCategorySplitChargeRule'
      { $sel:parameters:CostCategorySplitChargeRule' :: Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
parameters =
          forall a. Maybe a
Prelude.Nothing,
        $sel:source:CostCategorySplitChargeRule' :: Text
source = Text
pSource_,
        $sel:targets:CostCategorySplitChargeRule' :: NonEmpty Text
targets = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pTargets_,
        $sel:method:CostCategorySplitChargeRule' :: CostCategorySplitChargeMethod
method = CostCategorySplitChargeMethod
pMethod_
      }

-- | The parameters for a split charge method. This is only required for the
-- @FIXED@ method.
costCategorySplitChargeRule_parameters :: Lens.Lens' CostCategorySplitChargeRule (Prelude.Maybe (Prelude.NonEmpty CostCategorySplitChargeRuleParameter))
costCategorySplitChargeRule_parameters :: Lens'
  CostCategorySplitChargeRule
  (Maybe (NonEmpty CostCategorySplitChargeRuleParameter))
costCategorySplitChargeRule_parameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CostCategorySplitChargeRule' {Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
parameters :: Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
$sel:parameters:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule
-> Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
parameters} -> Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
parameters) (\s :: CostCategorySplitChargeRule
s@CostCategorySplitChargeRule' {} Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
a -> CostCategorySplitChargeRule
s {$sel:parameters:CostCategorySplitChargeRule' :: Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
parameters = Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
a} :: CostCategorySplitChargeRule) 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 Cost Category value that you want to split. That value can\'t be
-- used as a source or a target in other split charge rules. To indicate
-- uncategorized costs, you can use an empty string as the source.
costCategorySplitChargeRule_source :: Lens.Lens' CostCategorySplitChargeRule Prelude.Text
costCategorySplitChargeRule_source :: Lens' CostCategorySplitChargeRule Text
costCategorySplitChargeRule_source = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CostCategorySplitChargeRule' {Text
source :: Text
$sel:source:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> Text
source} -> Text
source) (\s :: CostCategorySplitChargeRule
s@CostCategorySplitChargeRule' {} Text
a -> CostCategorySplitChargeRule
s {$sel:source:CostCategorySplitChargeRule' :: Text
source = Text
a} :: CostCategorySplitChargeRule)

-- | The Cost Category values that you want to split costs across. These
-- values can\'t be used as a source in other split charge rules.
costCategorySplitChargeRule_targets :: Lens.Lens' CostCategorySplitChargeRule (Prelude.NonEmpty Prelude.Text)
costCategorySplitChargeRule_targets :: Lens' CostCategorySplitChargeRule (NonEmpty Text)
costCategorySplitChargeRule_targets = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CostCategorySplitChargeRule' {NonEmpty Text
targets :: NonEmpty Text
$sel:targets:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> NonEmpty Text
targets} -> NonEmpty Text
targets) (\s :: CostCategorySplitChargeRule
s@CostCategorySplitChargeRule' {} NonEmpty Text
a -> CostCategorySplitChargeRule
s {$sel:targets:CostCategorySplitChargeRule' :: NonEmpty Text
targets = NonEmpty Text
a} :: CostCategorySplitChargeRule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The method that\'s used to define how to split your source costs across
-- your targets.
--
-- @Proportional@ - Allocates charges across your targets based on the
-- proportional weighted cost of each target.
--
-- @Fixed@ - Allocates charges across your targets based on your defined
-- allocation percentage.
--
-- >@Even@ - Allocates costs evenly across all targets.
costCategorySplitChargeRule_method :: Lens.Lens' CostCategorySplitChargeRule CostCategorySplitChargeMethod
costCategorySplitChargeRule_method :: Lens' CostCategorySplitChargeRule CostCategorySplitChargeMethod
costCategorySplitChargeRule_method = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CostCategorySplitChargeRule' {CostCategorySplitChargeMethod
method :: CostCategorySplitChargeMethod
$sel:method:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> CostCategorySplitChargeMethod
method} -> CostCategorySplitChargeMethod
method) (\s :: CostCategorySplitChargeRule
s@CostCategorySplitChargeRule' {} CostCategorySplitChargeMethod
a -> CostCategorySplitChargeRule
s {$sel:method:CostCategorySplitChargeRule' :: CostCategorySplitChargeMethod
method = CostCategorySplitChargeMethod
a} :: CostCategorySplitChargeRule)

instance Data.FromJSON CostCategorySplitChargeRule where
  parseJSON :: Value -> Parser CostCategorySplitChargeRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CostCategorySplitChargeRule"
      ( \Object
x ->
          Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
-> Text
-> NonEmpty Text
-> CostCategorySplitChargeMethod
-> CostCategorySplitChargeRule
CostCategorySplitChargeRule'
            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
"Parameters")
            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
"Source")
            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
"Targets")
            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
"Method")
      )

instance Prelude.Hashable CostCategorySplitChargeRule where
  hashWithSalt :: Int -> CostCategorySplitChargeRule -> Int
hashWithSalt Int
_salt CostCategorySplitChargeRule' {Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
NonEmpty Text
Text
CostCategorySplitChargeMethod
method :: CostCategorySplitChargeMethod
targets :: NonEmpty Text
source :: Text
parameters :: Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
$sel:method:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> CostCategorySplitChargeMethod
$sel:targets:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> NonEmpty Text
$sel:source:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> Text
$sel:parameters:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule
-> Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
parameters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
source
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
targets
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` CostCategorySplitChargeMethod
method

instance Prelude.NFData CostCategorySplitChargeRule where
  rnf :: CostCategorySplitChargeRule -> ()
rnf CostCategorySplitChargeRule' {Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
NonEmpty Text
Text
CostCategorySplitChargeMethod
method :: CostCategorySplitChargeMethod
targets :: NonEmpty Text
source :: Text
parameters :: Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
$sel:method:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> CostCategorySplitChargeMethod
$sel:targets:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> NonEmpty Text
$sel:source:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> Text
$sel:parameters:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule
-> Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
parameters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
source
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
targets
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf CostCategorySplitChargeMethod
method

instance Data.ToJSON CostCategorySplitChargeRule where
  toJSON :: CostCategorySplitChargeRule -> Value
toJSON CostCategorySplitChargeRule' {Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
NonEmpty Text
Text
CostCategorySplitChargeMethod
method :: CostCategorySplitChargeMethod
targets :: NonEmpty Text
source :: Text
parameters :: Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
$sel:method:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> CostCategorySplitChargeMethod
$sel:targets:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> NonEmpty Text
$sel:source:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule -> Text
$sel:parameters:CostCategorySplitChargeRule' :: CostCategorySplitChargeRule
-> Maybe (NonEmpty CostCategorySplitChargeRuleParameter)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Parameters" 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 CostCategorySplitChargeRuleParameter)
parameters,
            forall a. a -> Maybe a
Prelude.Just (Key
"Source" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
source),
            forall a. a -> Maybe a
Prelude.Just (Key
"Targets" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
targets),
            forall a. a -> Maybe a
Prelude.Just (Key
"Method" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= CostCategorySplitChargeMethod
method)
          ]
      )