{-# 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.IoT.Types.AggregationType
-- 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.IoT.Types.AggregationType where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types.AggregationTypeName
import qualified Amazonka.Prelude as Prelude

-- | The type of aggregation queries.
--
-- /See:/ 'newAggregationType' smart constructor.
data AggregationType = AggregationType'
  { -- | A list of the values of aggregation types.
    AggregationType -> Maybe [Text]
values :: Prelude.Maybe [Prelude.Text],
    -- | The name of the aggregation type.
    AggregationType -> AggregationTypeName
name :: AggregationTypeName
  }
  deriving (AggregationType -> AggregationType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AggregationType -> AggregationType -> Bool
$c/= :: AggregationType -> AggregationType -> Bool
== :: AggregationType -> AggregationType -> Bool
$c== :: AggregationType -> AggregationType -> Bool
Prelude.Eq, ReadPrec [AggregationType]
ReadPrec AggregationType
Int -> ReadS AggregationType
ReadS [AggregationType]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AggregationType]
$creadListPrec :: ReadPrec [AggregationType]
readPrec :: ReadPrec AggregationType
$creadPrec :: ReadPrec AggregationType
readList :: ReadS [AggregationType]
$creadList :: ReadS [AggregationType]
readsPrec :: Int -> ReadS AggregationType
$creadsPrec :: Int -> ReadS AggregationType
Prelude.Read, Int -> AggregationType -> ShowS
[AggregationType] -> ShowS
AggregationType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AggregationType] -> ShowS
$cshowList :: [AggregationType] -> ShowS
show :: AggregationType -> String
$cshow :: AggregationType -> String
showsPrec :: Int -> AggregationType -> ShowS
$cshowsPrec :: Int -> AggregationType -> ShowS
Prelude.Show, forall x. Rep AggregationType x -> AggregationType
forall x. AggregationType -> Rep AggregationType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AggregationType x -> AggregationType
$cfrom :: forall x. AggregationType -> Rep AggregationType x
Prelude.Generic)

-- |
-- Create a value of 'AggregationType' 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:
--
-- 'values', 'aggregationType_values' - A list of the values of aggregation types.
--
-- 'name', 'aggregationType_name' - The name of the aggregation type.
newAggregationType ::
  -- | 'name'
  AggregationTypeName ->
  AggregationType
newAggregationType :: AggregationTypeName -> AggregationType
newAggregationType AggregationTypeName
pName_ =
  AggregationType'
    { $sel:values:AggregationType' :: Maybe [Text]
values = forall a. Maybe a
Prelude.Nothing,
      $sel:name:AggregationType' :: AggregationTypeName
name = AggregationTypeName
pName_
    }

-- | A list of the values of aggregation types.
aggregationType_values :: Lens.Lens' AggregationType (Prelude.Maybe [Prelude.Text])
aggregationType_values :: Lens' AggregationType (Maybe [Text])
aggregationType_values = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AggregationType' {Maybe [Text]
values :: Maybe [Text]
$sel:values:AggregationType' :: AggregationType -> Maybe [Text]
values} -> Maybe [Text]
values) (\s :: AggregationType
s@AggregationType' {} Maybe [Text]
a -> AggregationType
s {$sel:values:AggregationType' :: Maybe [Text]
values = Maybe [Text]
a} :: AggregationType) 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 name of the aggregation type.
aggregationType_name :: Lens.Lens' AggregationType AggregationTypeName
aggregationType_name :: Lens' AggregationType AggregationTypeName
aggregationType_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AggregationType' {AggregationTypeName
name :: AggregationTypeName
$sel:name:AggregationType' :: AggregationType -> AggregationTypeName
name} -> AggregationTypeName
name) (\s :: AggregationType
s@AggregationType' {} AggregationTypeName
a -> AggregationType
s {$sel:name:AggregationType' :: AggregationTypeName
name = AggregationTypeName
a} :: AggregationType)

instance Data.FromJSON AggregationType where
  parseJSON :: Value -> Parser AggregationType
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AggregationType"
      ( \Object
x ->
          Maybe [Text] -> AggregationTypeName -> AggregationType
AggregationType'
            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
"values" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"name")
      )

instance Prelude.Hashable AggregationType where
  hashWithSalt :: Int -> AggregationType -> Int
hashWithSalt Int
_salt AggregationType' {Maybe [Text]
AggregationTypeName
name :: AggregationTypeName
values :: Maybe [Text]
$sel:name:AggregationType' :: AggregationType -> AggregationTypeName
$sel:values:AggregationType' :: AggregationType -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
values
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AggregationTypeName
name

instance Prelude.NFData AggregationType where
  rnf :: AggregationType -> ()
rnf AggregationType' {Maybe [Text]
AggregationTypeName
name :: AggregationTypeName
values :: Maybe [Text]
$sel:name:AggregationType' :: AggregationType -> AggregationTypeName
$sel:values:AggregationType' :: AggregationType -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
values seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf AggregationTypeName
name

instance Data.ToJSON AggregationType where
  toJSON :: AggregationType -> Value
toJSON AggregationType' {Maybe [Text]
AggregationTypeName
name :: AggregationTypeName
values :: Maybe [Text]
$sel:name:AggregationType' :: AggregationType -> AggregationTypeName
$sel:values:AggregationType' :: AggregationType -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"values" 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 [Text]
values,
            forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= AggregationTypeName
name)
          ]
      )