{-# 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.LookoutMetrics.Types.AlertFilters
-- 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.LookoutMetrics.Types.AlertFilters where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LookoutMetrics.Types.DimensionFilter
import qualified Amazonka.Prelude as Prelude

-- | The configuration of the alert filters.
--
-- /See:/ 'newAlertFilters' smart constructor.
data AlertFilters = AlertFilters'
  { -- | The list of DimensionFilter objects that are used for dimension-based
    -- filtering.
    AlertFilters -> Maybe (NonEmpty DimensionFilter)
dimensionFilterList :: Prelude.Maybe (Prelude.NonEmpty DimensionFilter),
    -- | The list of measures that you want to get alerts for.
    AlertFilters -> Maybe (NonEmpty Text)
metricList :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (AlertFilters -> AlertFilters -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AlertFilters -> AlertFilters -> Bool
$c/= :: AlertFilters -> AlertFilters -> Bool
== :: AlertFilters -> AlertFilters -> Bool
$c== :: AlertFilters -> AlertFilters -> Bool
Prelude.Eq, ReadPrec [AlertFilters]
ReadPrec AlertFilters
Int -> ReadS AlertFilters
ReadS [AlertFilters]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AlertFilters]
$creadListPrec :: ReadPrec [AlertFilters]
readPrec :: ReadPrec AlertFilters
$creadPrec :: ReadPrec AlertFilters
readList :: ReadS [AlertFilters]
$creadList :: ReadS [AlertFilters]
readsPrec :: Int -> ReadS AlertFilters
$creadsPrec :: Int -> ReadS AlertFilters
Prelude.Read, Int -> AlertFilters -> ShowS
[AlertFilters] -> ShowS
AlertFilters -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AlertFilters] -> ShowS
$cshowList :: [AlertFilters] -> ShowS
show :: AlertFilters -> String
$cshow :: AlertFilters -> String
showsPrec :: Int -> AlertFilters -> ShowS
$cshowsPrec :: Int -> AlertFilters -> ShowS
Prelude.Show, forall x. Rep AlertFilters x -> AlertFilters
forall x. AlertFilters -> Rep AlertFilters x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AlertFilters x -> AlertFilters
$cfrom :: forall x. AlertFilters -> Rep AlertFilters x
Prelude.Generic)

-- |
-- Create a value of 'AlertFilters' 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:
--
-- 'dimensionFilterList', 'alertFilters_dimensionFilterList' - The list of DimensionFilter objects that are used for dimension-based
-- filtering.
--
-- 'metricList', 'alertFilters_metricList' - The list of measures that you want to get alerts for.
newAlertFilters ::
  AlertFilters
newAlertFilters :: AlertFilters
newAlertFilters =
  AlertFilters'
    { $sel:dimensionFilterList:AlertFilters' :: Maybe (NonEmpty DimensionFilter)
dimensionFilterList =
        forall a. Maybe a
Prelude.Nothing,
      $sel:metricList:AlertFilters' :: Maybe (NonEmpty Text)
metricList = forall a. Maybe a
Prelude.Nothing
    }

-- | The list of DimensionFilter objects that are used for dimension-based
-- filtering.
alertFilters_dimensionFilterList :: Lens.Lens' AlertFilters (Prelude.Maybe (Prelude.NonEmpty DimensionFilter))
alertFilters_dimensionFilterList :: Lens' AlertFilters (Maybe (NonEmpty DimensionFilter))
alertFilters_dimensionFilterList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AlertFilters' {Maybe (NonEmpty DimensionFilter)
dimensionFilterList :: Maybe (NonEmpty DimensionFilter)
$sel:dimensionFilterList:AlertFilters' :: AlertFilters -> Maybe (NonEmpty DimensionFilter)
dimensionFilterList} -> Maybe (NonEmpty DimensionFilter)
dimensionFilterList) (\s :: AlertFilters
s@AlertFilters' {} Maybe (NonEmpty DimensionFilter)
a -> AlertFilters
s {$sel:dimensionFilterList:AlertFilters' :: Maybe (NonEmpty DimensionFilter)
dimensionFilterList = Maybe (NonEmpty DimensionFilter)
a} :: AlertFilters) 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 list of measures that you want to get alerts for.
alertFilters_metricList :: Lens.Lens' AlertFilters (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
alertFilters_metricList :: Lens' AlertFilters (Maybe (NonEmpty Text))
alertFilters_metricList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AlertFilters' {Maybe (NonEmpty Text)
metricList :: Maybe (NonEmpty Text)
$sel:metricList:AlertFilters' :: AlertFilters -> Maybe (NonEmpty Text)
metricList} -> Maybe (NonEmpty Text)
metricList) (\s :: AlertFilters
s@AlertFilters' {} Maybe (NonEmpty Text)
a -> AlertFilters
s {$sel:metricList:AlertFilters' :: Maybe (NonEmpty Text)
metricList = Maybe (NonEmpty Text)
a} :: AlertFilters) 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

instance Data.FromJSON AlertFilters where
  parseJSON :: Value -> Parser AlertFilters
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AlertFilters"
      ( \Object
x ->
          Maybe (NonEmpty DimensionFilter)
-> Maybe (NonEmpty Text) -> AlertFilters
AlertFilters'
            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
"DimensionFilterList")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MetricList")
      )

instance Prelude.Hashable AlertFilters where
  hashWithSalt :: Int -> AlertFilters -> Int
hashWithSalt Int
_salt AlertFilters' {Maybe (NonEmpty Text)
Maybe (NonEmpty DimensionFilter)
metricList :: Maybe (NonEmpty Text)
dimensionFilterList :: Maybe (NonEmpty DimensionFilter)
$sel:metricList:AlertFilters' :: AlertFilters -> Maybe (NonEmpty Text)
$sel:dimensionFilterList:AlertFilters' :: AlertFilters -> Maybe (NonEmpty DimensionFilter)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty DimensionFilter)
dimensionFilterList
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
metricList

instance Prelude.NFData AlertFilters where
  rnf :: AlertFilters -> ()
rnf AlertFilters' {Maybe (NonEmpty Text)
Maybe (NonEmpty DimensionFilter)
metricList :: Maybe (NonEmpty Text)
dimensionFilterList :: Maybe (NonEmpty DimensionFilter)
$sel:metricList:AlertFilters' :: AlertFilters -> Maybe (NonEmpty Text)
$sel:dimensionFilterList:AlertFilters' :: AlertFilters -> Maybe (NonEmpty DimensionFilter)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty DimensionFilter)
dimensionFilterList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
metricList

instance Data.ToJSON AlertFilters where
  toJSON :: AlertFilters -> Value
toJSON AlertFilters' {Maybe (NonEmpty Text)
Maybe (NonEmpty DimensionFilter)
metricList :: Maybe (NonEmpty Text)
dimensionFilterList :: Maybe (NonEmpty DimensionFilter)
$sel:metricList:AlertFilters' :: AlertFilters -> Maybe (NonEmpty Text)
$sel:dimensionFilterList:AlertFilters' :: AlertFilters -> Maybe (NonEmpty DimensionFilter)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DimensionFilterList" 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 DimensionFilter)
dimensionFilterList,
            (Key
"MetricList" 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 Text)
metricList
          ]
      )