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

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

-- | One level of grouped data in the results.
--
-- /See:/ 'newGroup' smart constructor.
data Group = Group'
  { -- | The metrics that are included in this group.
    Group -> Maybe (HashMap Text MetricValue)
metrics :: Prelude.Maybe (Prelude.HashMap Prelude.Text MetricValue),
    -- | The keys that are included in this group.
    Group -> Maybe [Text]
keys :: Prelude.Maybe [Prelude.Text]
  }
  deriving (Group -> Group -> Bool
(Group -> Group -> Bool) -> (Group -> Group -> Bool) -> Eq Group
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Group -> Group -> Bool
$c/= :: Group -> Group -> Bool
== :: Group -> Group -> Bool
$c== :: Group -> Group -> Bool
Prelude.Eq, ReadPrec [Group]
ReadPrec Group
Int -> ReadS Group
ReadS [Group]
(Int -> ReadS Group)
-> ReadS [Group]
-> ReadPrec Group
-> ReadPrec [Group]
-> Read Group
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Group]
$creadListPrec :: ReadPrec [Group]
readPrec :: ReadPrec Group
$creadPrec :: ReadPrec Group
readList :: ReadS [Group]
$creadList :: ReadS [Group]
readsPrec :: Int -> ReadS Group
$creadsPrec :: Int -> ReadS Group
Prelude.Read, Int -> Group -> ShowS
[Group] -> ShowS
Group -> String
(Int -> Group -> ShowS)
-> (Group -> String) -> ([Group] -> ShowS) -> Show Group
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Group] -> ShowS
$cshowList :: [Group] -> ShowS
show :: Group -> String
$cshow :: Group -> String
showsPrec :: Int -> Group -> ShowS
$cshowsPrec :: Int -> Group -> ShowS
Prelude.Show, (forall x. Group -> Rep Group x)
-> (forall x. Rep Group x -> Group) -> Generic Group
forall x. Rep Group x -> Group
forall x. Group -> Rep Group x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Group x -> Group
$cfrom :: forall x. Group -> Rep Group x
Prelude.Generic)

-- |
-- Create a value of 'Group' 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:
--
-- 'metrics', 'group_metrics' - The metrics that are included in this group.
--
-- 'keys', 'group_keys' - The keys that are included in this group.
newGroup ::
  Group
newGroup :: Group
newGroup =
  Group' :: Maybe (HashMap Text MetricValue) -> Maybe [Text] -> Group
Group'
    { $sel:metrics:Group' :: Maybe (HashMap Text MetricValue)
metrics = Maybe (HashMap Text MetricValue)
forall a. Maybe a
Prelude.Nothing,
      $sel:keys:Group' :: Maybe [Text]
keys = Maybe [Text]
forall a. Maybe a
Prelude.Nothing
    }

-- | The metrics that are included in this group.
group_metrics :: Lens.Lens' Group (Prelude.Maybe (Prelude.HashMap Prelude.Text MetricValue))
group_metrics :: (Maybe (HashMap Text MetricValue)
 -> f (Maybe (HashMap Text MetricValue)))
-> Group -> f Group
group_metrics = (Group -> Maybe (HashMap Text MetricValue))
-> (Group -> Maybe (HashMap Text MetricValue) -> Group)
-> Lens
     Group
     Group
     (Maybe (HashMap Text MetricValue))
     (Maybe (HashMap Text MetricValue))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Group' {Maybe (HashMap Text MetricValue)
metrics :: Maybe (HashMap Text MetricValue)
$sel:metrics:Group' :: Group -> Maybe (HashMap Text MetricValue)
metrics} -> Maybe (HashMap Text MetricValue)
metrics) (\s :: Group
s@Group' {} Maybe (HashMap Text MetricValue)
a -> Group
s {$sel:metrics:Group' :: Maybe (HashMap Text MetricValue)
metrics = Maybe (HashMap Text MetricValue)
a} :: Group) ((Maybe (HashMap Text MetricValue)
  -> f (Maybe (HashMap Text MetricValue)))
 -> Group -> f Group)
-> ((Maybe (HashMap Text MetricValue)
     -> f (Maybe (HashMap Text MetricValue)))
    -> Maybe (HashMap Text MetricValue)
    -> f (Maybe (HashMap Text MetricValue)))
-> (Maybe (HashMap Text MetricValue)
    -> f (Maybe (HashMap Text MetricValue)))
-> Group
-> f Group
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
-> Iso
     (Maybe (HashMap Text MetricValue))
     (Maybe (HashMap Text MetricValue))
     (Maybe (HashMap Text MetricValue))
     (Maybe (HashMap Text MetricValue))
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
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The keys that are included in this group.
group_keys :: Lens.Lens' Group (Prelude.Maybe [Prelude.Text])
group_keys :: (Maybe [Text] -> f (Maybe [Text])) -> Group -> f Group
group_keys = (Group -> Maybe [Text])
-> (Group -> Maybe [Text] -> Group)
-> Lens Group Group (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Group' {Maybe [Text]
keys :: Maybe [Text]
$sel:keys:Group' :: Group -> Maybe [Text]
keys} -> Maybe [Text]
keys) (\s :: Group
s@Group' {} Maybe [Text]
a -> Group
s {$sel:keys:Group' :: Maybe [Text]
keys = Maybe [Text]
a} :: Group) ((Maybe [Text] -> f (Maybe [Text])) -> Group -> f Group)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> Group
-> f Group
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Group where
  parseJSON :: Value -> Parser Group
parseJSON =
    String -> (Object -> Parser Group) -> Value -> Parser Group
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Group"
      ( \Object
x ->
          Maybe (HashMap Text MetricValue) -> Maybe [Text] -> Group
Group'
            (Maybe (HashMap Text MetricValue) -> Maybe [Text] -> Group)
-> Parser (Maybe (HashMap Text MetricValue))
-> Parser (Maybe [Text] -> Group)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text MetricValue)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Metrics" Parser (Maybe (Maybe (HashMap Text MetricValue)))
-> Maybe (HashMap Text MetricValue)
-> Parser (Maybe (HashMap Text MetricValue))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text MetricValue)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe [Text] -> Group)
-> Parser (Maybe [Text]) -> Parser Group
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Keys" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Group

instance Prelude.NFData Group