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

import qualified Amazonka.Core as Core
import Amazonka.CostExplorer.Types.CostCategoryInheritedValueDimension
import Amazonka.CostExplorer.Types.CostCategoryRuleType
import Amazonka.CostExplorer.Types.Expression
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Rules are processed in order. If there are multiple rules that match the
-- line item, then the first rule to match is used to determine that Cost
-- Category value.
--
-- /See:/ 'newCostCategoryRule' smart constructor.
data CostCategoryRule = CostCategoryRule'
  { -- | The value the line item is categorized as if the line item contains the
    -- matched dimension.
    CostCategoryRule -> Maybe CostCategoryInheritedValueDimension
inheritedValue :: Prelude.Maybe CostCategoryInheritedValueDimension,
    CostCategoryRule -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | An
    -- <https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_Expression.html Expression>
    -- object used to categorize costs. This supports dimensions, tags, and
    -- nested expressions. Currently the only dimensions supported are
    -- @LINKED_ACCOUNT@, @SERVICE_CODE@, @RECORD_TYPE@, and
    -- @LINKED_ACCOUNT_NAME@.
    --
    -- Root level @OR@ isn\'t supported. We recommend that you create a
    -- separate rule instead.
    --
    -- @RECORD_TYPE@ is a dimension used for Cost Explorer APIs, and is also
    -- supported for Cost Category expressions. This dimension uses different
    -- terms, depending on whether you\'re using the console or API\/JSON
    -- editor. For a detailed comparison, see
    -- <https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/manage-cost-categories.html#cost-categories-terms Term Comparisons>
    -- in the /Billing and Cost Management User Guide/.
    CostCategoryRule -> Maybe Expression
rule :: Prelude.Maybe Expression,
    -- | You can define the @CostCategoryRule@ rule type as either @REGULAR@ or
    -- @INHERITED_VALUE@. The @INHERITED_VALUE@ rule type adds the flexibility
    -- of defining a rule that dynamically inherits the cost category value
    -- from the dimension value defined by
    -- @CostCategoryInheritedValueDimension@. For example, if you want to
    -- dynamically group costs based on the value of a specific tag key, first
    -- choose an inherited value rule type, then choose the tag dimension and
    -- specify the tag key to use.
    CostCategoryRule -> Maybe CostCategoryRuleType
type' :: Prelude.Maybe CostCategoryRuleType
  }
  deriving (CostCategoryRule -> CostCategoryRule -> Bool
(CostCategoryRule -> CostCategoryRule -> Bool)
-> (CostCategoryRule -> CostCategoryRule -> Bool)
-> Eq CostCategoryRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CostCategoryRule -> CostCategoryRule -> Bool
$c/= :: CostCategoryRule -> CostCategoryRule -> Bool
== :: CostCategoryRule -> CostCategoryRule -> Bool
$c== :: CostCategoryRule -> CostCategoryRule -> Bool
Prelude.Eq, ReadPrec [CostCategoryRule]
ReadPrec CostCategoryRule
Int -> ReadS CostCategoryRule
ReadS [CostCategoryRule]
(Int -> ReadS CostCategoryRule)
-> ReadS [CostCategoryRule]
-> ReadPrec CostCategoryRule
-> ReadPrec [CostCategoryRule]
-> Read CostCategoryRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CostCategoryRule]
$creadListPrec :: ReadPrec [CostCategoryRule]
readPrec :: ReadPrec CostCategoryRule
$creadPrec :: ReadPrec CostCategoryRule
readList :: ReadS [CostCategoryRule]
$creadList :: ReadS [CostCategoryRule]
readsPrec :: Int -> ReadS CostCategoryRule
$creadsPrec :: Int -> ReadS CostCategoryRule
Prelude.Read, Int -> CostCategoryRule -> ShowS
[CostCategoryRule] -> ShowS
CostCategoryRule -> String
(Int -> CostCategoryRule -> ShowS)
-> (CostCategoryRule -> String)
-> ([CostCategoryRule] -> ShowS)
-> Show CostCategoryRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CostCategoryRule] -> ShowS
$cshowList :: [CostCategoryRule] -> ShowS
show :: CostCategoryRule -> String
$cshow :: CostCategoryRule -> String
showsPrec :: Int -> CostCategoryRule -> ShowS
$cshowsPrec :: Int -> CostCategoryRule -> ShowS
Prelude.Show, (forall x. CostCategoryRule -> Rep CostCategoryRule x)
-> (forall x. Rep CostCategoryRule x -> CostCategoryRule)
-> Generic CostCategoryRule
forall x. Rep CostCategoryRule x -> CostCategoryRule
forall x. CostCategoryRule -> Rep CostCategoryRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CostCategoryRule x -> CostCategoryRule
$cfrom :: forall x. CostCategoryRule -> Rep CostCategoryRule x
Prelude.Generic)

-- |
-- Create a value of 'CostCategoryRule' 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:
--
-- 'inheritedValue', 'costCategoryRule_inheritedValue' - The value the line item is categorized as if the line item contains the
-- matched dimension.
--
-- 'value', 'costCategoryRule_value' - Undocumented member.
--
-- 'rule', 'costCategoryRule_rule' - An
-- <https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_Expression.html Expression>
-- object used to categorize costs. This supports dimensions, tags, and
-- nested expressions. Currently the only dimensions supported are
-- @LINKED_ACCOUNT@, @SERVICE_CODE@, @RECORD_TYPE@, and
-- @LINKED_ACCOUNT_NAME@.
--
-- Root level @OR@ isn\'t supported. We recommend that you create a
-- separate rule instead.
--
-- @RECORD_TYPE@ is a dimension used for Cost Explorer APIs, and is also
-- supported for Cost Category expressions. This dimension uses different
-- terms, depending on whether you\'re using the console or API\/JSON
-- editor. For a detailed comparison, see
-- <https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/manage-cost-categories.html#cost-categories-terms Term Comparisons>
-- in the /Billing and Cost Management User Guide/.
--
-- 'type'', 'costCategoryRule_type' - You can define the @CostCategoryRule@ rule type as either @REGULAR@ or
-- @INHERITED_VALUE@. The @INHERITED_VALUE@ rule type adds the flexibility
-- of defining a rule that dynamically inherits the cost category value
-- from the dimension value defined by
-- @CostCategoryInheritedValueDimension@. For example, if you want to
-- dynamically group costs based on the value of a specific tag key, first
-- choose an inherited value rule type, then choose the tag dimension and
-- specify the tag key to use.
newCostCategoryRule ::
  CostCategoryRule
newCostCategoryRule :: CostCategoryRule
newCostCategoryRule =
  CostCategoryRule' :: Maybe CostCategoryInheritedValueDimension
-> Maybe Text
-> Maybe Expression
-> Maybe CostCategoryRuleType
-> CostCategoryRule
CostCategoryRule'
    { $sel:inheritedValue:CostCategoryRule' :: Maybe CostCategoryInheritedValueDimension
inheritedValue = Maybe CostCategoryInheritedValueDimension
forall a. Maybe a
Prelude.Nothing,
      $sel:value:CostCategoryRule' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:rule:CostCategoryRule' :: Maybe Expression
rule = Maybe Expression
forall a. Maybe a
Prelude.Nothing,
      $sel:type':CostCategoryRule' :: Maybe CostCategoryRuleType
type' = Maybe CostCategoryRuleType
forall a. Maybe a
Prelude.Nothing
    }

-- | The value the line item is categorized as if the line item contains the
-- matched dimension.
costCategoryRule_inheritedValue :: Lens.Lens' CostCategoryRule (Prelude.Maybe CostCategoryInheritedValueDimension)
costCategoryRule_inheritedValue :: (Maybe CostCategoryInheritedValueDimension
 -> f (Maybe CostCategoryInheritedValueDimension))
-> CostCategoryRule -> f CostCategoryRule
costCategoryRule_inheritedValue = (CostCategoryRule -> Maybe CostCategoryInheritedValueDimension)
-> (CostCategoryRule
    -> Maybe CostCategoryInheritedValueDimension -> CostCategoryRule)
-> Lens
     CostCategoryRule
     CostCategoryRule
     (Maybe CostCategoryInheritedValueDimension)
     (Maybe CostCategoryInheritedValueDimension)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CostCategoryRule' {Maybe CostCategoryInheritedValueDimension
inheritedValue :: Maybe CostCategoryInheritedValueDimension
$sel:inheritedValue:CostCategoryRule' :: CostCategoryRule -> Maybe CostCategoryInheritedValueDimension
inheritedValue} -> Maybe CostCategoryInheritedValueDimension
inheritedValue) (\s :: CostCategoryRule
s@CostCategoryRule' {} Maybe CostCategoryInheritedValueDimension
a -> CostCategoryRule
s {$sel:inheritedValue:CostCategoryRule' :: Maybe CostCategoryInheritedValueDimension
inheritedValue = Maybe CostCategoryInheritedValueDimension
a} :: CostCategoryRule)

-- | Undocumented member.
costCategoryRule_value :: Lens.Lens' CostCategoryRule (Prelude.Maybe Prelude.Text)
costCategoryRule_value :: (Maybe Text -> f (Maybe Text))
-> CostCategoryRule -> f CostCategoryRule
costCategoryRule_value = (CostCategoryRule -> Maybe Text)
-> (CostCategoryRule -> Maybe Text -> CostCategoryRule)
-> Lens CostCategoryRule CostCategoryRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CostCategoryRule' {Maybe Text
value :: Maybe Text
$sel:value:CostCategoryRule' :: CostCategoryRule -> Maybe Text
value} -> Maybe Text
value) (\s :: CostCategoryRule
s@CostCategoryRule' {} Maybe Text
a -> CostCategoryRule
s {$sel:value:CostCategoryRule' :: Maybe Text
value = Maybe Text
a} :: CostCategoryRule)

-- | An
-- <https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_Expression.html Expression>
-- object used to categorize costs. This supports dimensions, tags, and
-- nested expressions. Currently the only dimensions supported are
-- @LINKED_ACCOUNT@, @SERVICE_CODE@, @RECORD_TYPE@, and
-- @LINKED_ACCOUNT_NAME@.
--
-- Root level @OR@ isn\'t supported. We recommend that you create a
-- separate rule instead.
--
-- @RECORD_TYPE@ is a dimension used for Cost Explorer APIs, and is also
-- supported for Cost Category expressions. This dimension uses different
-- terms, depending on whether you\'re using the console or API\/JSON
-- editor. For a detailed comparison, see
-- <https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/manage-cost-categories.html#cost-categories-terms Term Comparisons>
-- in the /Billing and Cost Management User Guide/.
costCategoryRule_rule :: Lens.Lens' CostCategoryRule (Prelude.Maybe Expression)
costCategoryRule_rule :: (Maybe Expression -> f (Maybe Expression))
-> CostCategoryRule -> f CostCategoryRule
costCategoryRule_rule = (CostCategoryRule -> Maybe Expression)
-> (CostCategoryRule -> Maybe Expression -> CostCategoryRule)
-> Lens
     CostCategoryRule
     CostCategoryRule
     (Maybe Expression)
     (Maybe Expression)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CostCategoryRule' {Maybe Expression
rule :: Maybe Expression
$sel:rule:CostCategoryRule' :: CostCategoryRule -> Maybe Expression
rule} -> Maybe Expression
rule) (\s :: CostCategoryRule
s@CostCategoryRule' {} Maybe Expression
a -> CostCategoryRule
s {$sel:rule:CostCategoryRule' :: Maybe Expression
rule = Maybe Expression
a} :: CostCategoryRule)

-- | You can define the @CostCategoryRule@ rule type as either @REGULAR@ or
-- @INHERITED_VALUE@. The @INHERITED_VALUE@ rule type adds the flexibility
-- of defining a rule that dynamically inherits the cost category value
-- from the dimension value defined by
-- @CostCategoryInheritedValueDimension@. For example, if you want to
-- dynamically group costs based on the value of a specific tag key, first
-- choose an inherited value rule type, then choose the tag dimension and
-- specify the tag key to use.
costCategoryRule_type :: Lens.Lens' CostCategoryRule (Prelude.Maybe CostCategoryRuleType)
costCategoryRule_type :: (Maybe CostCategoryRuleType -> f (Maybe CostCategoryRuleType))
-> CostCategoryRule -> f CostCategoryRule
costCategoryRule_type = (CostCategoryRule -> Maybe CostCategoryRuleType)
-> (CostCategoryRule
    -> Maybe CostCategoryRuleType -> CostCategoryRule)
-> Lens
     CostCategoryRule
     CostCategoryRule
     (Maybe CostCategoryRuleType)
     (Maybe CostCategoryRuleType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CostCategoryRule' {Maybe CostCategoryRuleType
type' :: Maybe CostCategoryRuleType
$sel:type':CostCategoryRule' :: CostCategoryRule -> Maybe CostCategoryRuleType
type'} -> Maybe CostCategoryRuleType
type') (\s :: CostCategoryRule
s@CostCategoryRule' {} Maybe CostCategoryRuleType
a -> CostCategoryRule
s {$sel:type':CostCategoryRule' :: Maybe CostCategoryRuleType
type' = Maybe CostCategoryRuleType
a} :: CostCategoryRule)

instance Core.FromJSON CostCategoryRule where
  parseJSON :: Value -> Parser CostCategoryRule
parseJSON =
    String
-> (Object -> Parser CostCategoryRule)
-> Value
-> Parser CostCategoryRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CostCategoryRule"
      ( \Object
x ->
          Maybe CostCategoryInheritedValueDimension
-> Maybe Text
-> Maybe Expression
-> Maybe CostCategoryRuleType
-> CostCategoryRule
CostCategoryRule'
            (Maybe CostCategoryInheritedValueDimension
 -> Maybe Text
 -> Maybe Expression
 -> Maybe CostCategoryRuleType
 -> CostCategoryRule)
-> Parser (Maybe CostCategoryInheritedValueDimension)
-> Parser
     (Maybe Text
      -> Maybe Expression
      -> Maybe CostCategoryRuleType
      -> CostCategoryRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object
-> Text -> Parser (Maybe CostCategoryInheritedValueDimension)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"InheritedValue")
            Parser
  (Maybe Text
   -> Maybe Expression
   -> Maybe CostCategoryRuleType
   -> CostCategoryRule)
-> Parser (Maybe Text)
-> Parser
     (Maybe Expression
      -> Maybe CostCategoryRuleType -> CostCategoryRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Value")
            Parser
  (Maybe Expression
   -> Maybe CostCategoryRuleType -> CostCategoryRule)
-> Parser (Maybe Expression)
-> Parser (Maybe CostCategoryRuleType -> CostCategoryRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Expression)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Rule")
            Parser (Maybe CostCategoryRuleType -> CostCategoryRule)
-> Parser (Maybe CostCategoryRuleType) -> Parser CostCategoryRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe CostCategoryRuleType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Type")
      )

instance Prelude.Hashable CostCategoryRule

instance Prelude.NFData CostCategoryRule

instance Core.ToJSON CostCategoryRule where
  toJSON :: CostCategoryRule -> Value
toJSON CostCategoryRule' {Maybe Text
Maybe CostCategoryInheritedValueDimension
Maybe CostCategoryRuleType
Maybe Expression
type' :: Maybe CostCategoryRuleType
rule :: Maybe Expression
value :: Maybe Text
inheritedValue :: Maybe CostCategoryInheritedValueDimension
$sel:type':CostCategoryRule' :: CostCategoryRule -> Maybe CostCategoryRuleType
$sel:rule:CostCategoryRule' :: CostCategoryRule -> Maybe Expression
$sel:value:CostCategoryRule' :: CostCategoryRule -> Maybe Text
$sel:inheritedValue:CostCategoryRule' :: CostCategoryRule -> Maybe CostCategoryInheritedValueDimension
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"InheritedValue" Text -> CostCategoryInheritedValueDimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (CostCategoryInheritedValueDimension -> Pair)
-> Maybe CostCategoryInheritedValueDimension -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CostCategoryInheritedValueDimension
inheritedValue,
            (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
value,
            (Text
"Rule" Text -> Expression -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Expression -> Pair) -> Maybe Expression -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Expression
rule,
            (Text
"Type" Text -> CostCategoryRuleType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (CostCategoryRuleType -> Pair)
-> Maybe CostCategoryRuleType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CostCategoryRuleType
type'
          ]
      )