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

import qualified Amazonka.Core as Core
import Amazonka.CostExplorer.Types.GroupDefinitionType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a group when you specify a group by criteria or in the
-- response to a query with a specific grouping.
--
-- /See:/ 'newGroupDefinition' smart constructor.
data GroupDefinition = GroupDefinition'
  { -- | The string that represents a key for a specified group.
    GroupDefinition -> Maybe Text
key :: Prelude.Maybe Prelude.Text,
    -- | The string that represents the type of group.
    GroupDefinition -> Maybe GroupDefinitionType
type' :: Prelude.Maybe GroupDefinitionType
  }
  deriving (GroupDefinition -> GroupDefinition -> Bool
(GroupDefinition -> GroupDefinition -> Bool)
-> (GroupDefinition -> GroupDefinition -> Bool)
-> Eq GroupDefinition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GroupDefinition -> GroupDefinition -> Bool
$c/= :: GroupDefinition -> GroupDefinition -> Bool
== :: GroupDefinition -> GroupDefinition -> Bool
$c== :: GroupDefinition -> GroupDefinition -> Bool
Prelude.Eq, ReadPrec [GroupDefinition]
ReadPrec GroupDefinition
Int -> ReadS GroupDefinition
ReadS [GroupDefinition]
(Int -> ReadS GroupDefinition)
-> ReadS [GroupDefinition]
-> ReadPrec GroupDefinition
-> ReadPrec [GroupDefinition]
-> Read GroupDefinition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GroupDefinition]
$creadListPrec :: ReadPrec [GroupDefinition]
readPrec :: ReadPrec GroupDefinition
$creadPrec :: ReadPrec GroupDefinition
readList :: ReadS [GroupDefinition]
$creadList :: ReadS [GroupDefinition]
readsPrec :: Int -> ReadS GroupDefinition
$creadsPrec :: Int -> ReadS GroupDefinition
Prelude.Read, Int -> GroupDefinition -> ShowS
[GroupDefinition] -> ShowS
GroupDefinition -> String
(Int -> GroupDefinition -> ShowS)
-> (GroupDefinition -> String)
-> ([GroupDefinition] -> ShowS)
-> Show GroupDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GroupDefinition] -> ShowS
$cshowList :: [GroupDefinition] -> ShowS
show :: GroupDefinition -> String
$cshow :: GroupDefinition -> String
showsPrec :: Int -> GroupDefinition -> ShowS
$cshowsPrec :: Int -> GroupDefinition -> ShowS
Prelude.Show, (forall x. GroupDefinition -> Rep GroupDefinition x)
-> (forall x. Rep GroupDefinition x -> GroupDefinition)
-> Generic GroupDefinition
forall x. Rep GroupDefinition x -> GroupDefinition
forall x. GroupDefinition -> Rep GroupDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GroupDefinition x -> GroupDefinition
$cfrom :: forall x. GroupDefinition -> Rep GroupDefinition x
Prelude.Generic)

-- |
-- Create a value of 'GroupDefinition' 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:
--
-- 'key', 'groupDefinition_key' - The string that represents a key for a specified group.
--
-- 'type'', 'groupDefinition_type' - The string that represents the type of group.
newGroupDefinition ::
  GroupDefinition
newGroupDefinition :: GroupDefinition
newGroupDefinition =
  GroupDefinition' :: Maybe Text -> Maybe GroupDefinitionType -> GroupDefinition
GroupDefinition'
    { $sel:key:GroupDefinition' :: Maybe Text
key = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':GroupDefinition' :: Maybe GroupDefinitionType
type' = Maybe GroupDefinitionType
forall a. Maybe a
Prelude.Nothing
    }

-- | The string that represents a key for a specified group.
groupDefinition_key :: Lens.Lens' GroupDefinition (Prelude.Maybe Prelude.Text)
groupDefinition_key :: (Maybe Text -> f (Maybe Text))
-> GroupDefinition -> f GroupDefinition
groupDefinition_key = (GroupDefinition -> Maybe Text)
-> (GroupDefinition -> Maybe Text -> GroupDefinition)
-> Lens GroupDefinition GroupDefinition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GroupDefinition' {Maybe Text
key :: Maybe Text
$sel:key:GroupDefinition' :: GroupDefinition -> Maybe Text
key} -> Maybe Text
key) (\s :: GroupDefinition
s@GroupDefinition' {} Maybe Text
a -> GroupDefinition
s {$sel:key:GroupDefinition' :: Maybe Text
key = Maybe Text
a} :: GroupDefinition)

-- | The string that represents the type of group.
groupDefinition_type :: Lens.Lens' GroupDefinition (Prelude.Maybe GroupDefinitionType)
groupDefinition_type :: (Maybe GroupDefinitionType -> f (Maybe GroupDefinitionType))
-> GroupDefinition -> f GroupDefinition
groupDefinition_type = (GroupDefinition -> Maybe GroupDefinitionType)
-> (GroupDefinition
    -> Maybe GroupDefinitionType -> GroupDefinition)
-> Lens
     GroupDefinition
     GroupDefinition
     (Maybe GroupDefinitionType)
     (Maybe GroupDefinitionType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GroupDefinition' {Maybe GroupDefinitionType
type' :: Maybe GroupDefinitionType
$sel:type':GroupDefinition' :: GroupDefinition -> Maybe GroupDefinitionType
type'} -> Maybe GroupDefinitionType
type') (\s :: GroupDefinition
s@GroupDefinition' {} Maybe GroupDefinitionType
a -> GroupDefinition
s {$sel:type':GroupDefinition' :: Maybe GroupDefinitionType
type' = Maybe GroupDefinitionType
a} :: GroupDefinition)

instance Core.FromJSON GroupDefinition where
  parseJSON :: Value -> Parser GroupDefinition
parseJSON =
    String
-> (Object -> Parser GroupDefinition)
-> Value
-> Parser GroupDefinition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GroupDefinition"
      ( \Object
x ->
          Maybe Text -> Maybe GroupDefinitionType -> GroupDefinition
GroupDefinition'
            (Maybe Text -> Maybe GroupDefinitionType -> GroupDefinition)
-> Parser (Maybe Text)
-> Parser (Maybe GroupDefinitionType -> GroupDefinition)
forall (f :: * -> *) a b. Functor 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
"Key") Parser (Maybe GroupDefinitionType -> GroupDefinition)
-> Parser (Maybe GroupDefinitionType) -> Parser GroupDefinition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe GroupDefinitionType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Type")
      )

instance Prelude.Hashable GroupDefinition

instance Prelude.NFData GroupDefinition

instance Core.ToJSON GroupDefinition where
  toJSON :: GroupDefinition -> Value
toJSON GroupDefinition' {Maybe Text
Maybe GroupDefinitionType
type' :: Maybe GroupDefinitionType
key :: Maybe Text
$sel:type':GroupDefinition' :: GroupDefinition -> Maybe GroupDefinitionType
$sel:key:GroupDefinition' :: GroupDefinition -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Key" 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
key,
            (Text
"Type" Text -> GroupDefinitionType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (GroupDefinitionType -> Pair)
-> Maybe GroupDefinitionType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe GroupDefinitionType
type'
          ]
      )