{-# 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.Pinpoint.Types.SetDimension
-- 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.Pinpoint.Types.SetDimension where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.DimensionType
import qualified Amazonka.Prelude as Prelude

-- | Specifies the dimension type and values for a segment dimension.
--
-- /See:/ 'newSetDimension' smart constructor.
data SetDimension = SetDimension'
  { -- | The type of segment dimension to use. Valid values are: INCLUSIVE,
    -- endpoints that match the criteria are included in the segment; and,
    -- EXCLUSIVE, endpoints that match the criteria are excluded from the
    -- segment.
    SetDimension -> Maybe DimensionType
dimensionType :: Prelude.Maybe DimensionType,
    -- | The criteria values to use for the segment dimension. Depending on the
    -- value of the DimensionType property, endpoints are included or excluded
    -- from the segment if their values match the criteria values.
    SetDimension -> [Text]
values :: [Prelude.Text]
  }
  deriving (SetDimension -> SetDimension -> Bool
(SetDimension -> SetDimension -> Bool)
-> (SetDimension -> SetDimension -> Bool) -> Eq SetDimension
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetDimension -> SetDimension -> Bool
$c/= :: SetDimension -> SetDimension -> Bool
== :: SetDimension -> SetDimension -> Bool
$c== :: SetDimension -> SetDimension -> Bool
Prelude.Eq, ReadPrec [SetDimension]
ReadPrec SetDimension
Int -> ReadS SetDimension
ReadS [SetDimension]
(Int -> ReadS SetDimension)
-> ReadS [SetDimension]
-> ReadPrec SetDimension
-> ReadPrec [SetDimension]
-> Read SetDimension
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SetDimension]
$creadListPrec :: ReadPrec [SetDimension]
readPrec :: ReadPrec SetDimension
$creadPrec :: ReadPrec SetDimension
readList :: ReadS [SetDimension]
$creadList :: ReadS [SetDimension]
readsPrec :: Int -> ReadS SetDimension
$creadsPrec :: Int -> ReadS SetDimension
Prelude.Read, Int -> SetDimension -> ShowS
[SetDimension] -> ShowS
SetDimension -> String
(Int -> SetDimension -> ShowS)
-> (SetDimension -> String)
-> ([SetDimension] -> ShowS)
-> Show SetDimension
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetDimension] -> ShowS
$cshowList :: [SetDimension] -> ShowS
show :: SetDimension -> String
$cshow :: SetDimension -> String
showsPrec :: Int -> SetDimension -> ShowS
$cshowsPrec :: Int -> SetDimension -> ShowS
Prelude.Show, (forall x. SetDimension -> Rep SetDimension x)
-> (forall x. Rep SetDimension x -> SetDimension)
-> Generic SetDimension
forall x. Rep SetDimension x -> SetDimension
forall x. SetDimension -> Rep SetDimension x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetDimension x -> SetDimension
$cfrom :: forall x. SetDimension -> Rep SetDimension x
Prelude.Generic)

-- |
-- Create a value of 'SetDimension' 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:
--
-- 'dimensionType', 'setDimension_dimensionType' - The type of segment dimension to use. Valid values are: INCLUSIVE,
-- endpoints that match the criteria are included in the segment; and,
-- EXCLUSIVE, endpoints that match the criteria are excluded from the
-- segment.
--
-- 'values', 'setDimension_values' - The criteria values to use for the segment dimension. Depending on the
-- value of the DimensionType property, endpoints are included or excluded
-- from the segment if their values match the criteria values.
newSetDimension ::
  SetDimension
newSetDimension :: SetDimension
newSetDimension =
  SetDimension' :: Maybe DimensionType -> [Text] -> SetDimension
SetDimension'
    { $sel:dimensionType:SetDimension' :: Maybe DimensionType
dimensionType = Maybe DimensionType
forall a. Maybe a
Prelude.Nothing,
      $sel:values:SetDimension' :: [Text]
values = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The type of segment dimension to use. Valid values are: INCLUSIVE,
-- endpoints that match the criteria are included in the segment; and,
-- EXCLUSIVE, endpoints that match the criteria are excluded from the
-- segment.
setDimension_dimensionType :: Lens.Lens' SetDimension (Prelude.Maybe DimensionType)
setDimension_dimensionType :: (Maybe DimensionType -> f (Maybe DimensionType))
-> SetDimension -> f SetDimension
setDimension_dimensionType = (SetDimension -> Maybe DimensionType)
-> (SetDimension -> Maybe DimensionType -> SetDimension)
-> Lens
     SetDimension
     SetDimension
     (Maybe DimensionType)
     (Maybe DimensionType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetDimension' {Maybe DimensionType
dimensionType :: Maybe DimensionType
$sel:dimensionType:SetDimension' :: SetDimension -> Maybe DimensionType
dimensionType} -> Maybe DimensionType
dimensionType) (\s :: SetDimension
s@SetDimension' {} Maybe DimensionType
a -> SetDimension
s {$sel:dimensionType:SetDimension' :: Maybe DimensionType
dimensionType = Maybe DimensionType
a} :: SetDimension)

-- | The criteria values to use for the segment dimension. Depending on the
-- value of the DimensionType property, endpoints are included or excluded
-- from the segment if their values match the criteria values.
setDimension_values :: Lens.Lens' SetDimension [Prelude.Text]
setDimension_values :: ([Text] -> f [Text]) -> SetDimension -> f SetDimension
setDimension_values = (SetDimension -> [Text])
-> (SetDimension -> [Text] -> SetDimension)
-> Lens SetDimension SetDimension [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetDimension' {[Text]
values :: [Text]
$sel:values:SetDimension' :: SetDimension -> [Text]
values} -> [Text]
values) (\s :: SetDimension
s@SetDimension' {} [Text]
a -> SetDimension
s {$sel:values:SetDimension' :: [Text]
values = [Text]
a} :: SetDimension) (([Text] -> f [Text]) -> SetDimension -> f SetDimension)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> SetDimension
-> f SetDimension
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON SetDimension where
  parseJSON :: Value -> Parser SetDimension
parseJSON =
    String
-> (Object -> Parser SetDimension) -> Value -> Parser SetDimension
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SetDimension"
      ( \Object
x ->
          Maybe DimensionType -> [Text] -> SetDimension
SetDimension'
            (Maybe DimensionType -> [Text] -> SetDimension)
-> Parser (Maybe DimensionType) -> Parser ([Text] -> SetDimension)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe DimensionType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DimensionType")
            Parser ([Text] -> SetDimension)
-> Parser [Text] -> Parser SetDimension
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
"Values" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable SetDimension

instance Prelude.NFData SetDimension

instance Core.ToJSON SetDimension where
  toJSON :: SetDimension -> Value
toJSON SetDimension' {[Text]
Maybe DimensionType
values :: [Text]
dimensionType :: Maybe DimensionType
$sel:values:SetDimension' :: SetDimension -> [Text]
$sel:dimensionType:SetDimension' :: SetDimension -> Maybe DimensionType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DimensionType" Text -> DimensionType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (DimensionType -> Pair) -> Maybe DimensionType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DimensionType
dimensionType,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Values" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
values)
          ]
      )