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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Pinpoint.Types.AttributeType
import qualified Amazonka.Prelude as Prelude

-- | Specifies attribute-based criteria for including or excluding endpoints
-- from a segment.
--
-- /See:/ 'newAttributeDimension' smart constructor.
data AttributeDimension = AttributeDimension'
  { -- | The type of segment dimension to use. Valid values are:
    --
    -- INCLUSIVE - endpoints that have attributes matching the values are
    -- included in the segment.
    --
    -- EXCLUSIVE - endpoints that have attributes matching the values are
    -- excluded in the segment.
    --
    -- CONTAINS - endpoints that have attributes\' substrings match the values
    -- are included in the segment.
    --
    -- BEFORE - endpoints with attributes read as ISO_INSTANT datetimes before
    -- the value are included in the segment.
    --
    -- AFTER - endpoints with attributes read as ISO_INSTANT datetimes after
    -- the value are included in the segment.
    --
    -- ON - endpoints with attributes read as ISO_INSTANT dates on the value
    -- are included in the segment. Time is ignored in this comparison.
    --
    -- BETWEEN - endpoints with attributes read as ISO_INSTANT datetimes
    -- between the values are included in the segment.
    AttributeDimension -> Maybe AttributeType
attributeType :: Prelude.Maybe AttributeType,
    -- | The criteria values to use for the segment dimension. Depending on the
    -- value of the AttributeType property, endpoints are included or excluded
    -- from the segment if their attribute values match the criteria values.
    AttributeDimension -> [Text]
values :: [Prelude.Text]
  }
  deriving (AttributeDimension -> AttributeDimension -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttributeDimension -> AttributeDimension -> Bool
$c/= :: AttributeDimension -> AttributeDimension -> Bool
== :: AttributeDimension -> AttributeDimension -> Bool
$c== :: AttributeDimension -> AttributeDimension -> Bool
Prelude.Eq, ReadPrec [AttributeDimension]
ReadPrec AttributeDimension
Int -> ReadS AttributeDimension
ReadS [AttributeDimension]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttributeDimension]
$creadListPrec :: ReadPrec [AttributeDimension]
readPrec :: ReadPrec AttributeDimension
$creadPrec :: ReadPrec AttributeDimension
readList :: ReadS [AttributeDimension]
$creadList :: ReadS [AttributeDimension]
readsPrec :: Int -> ReadS AttributeDimension
$creadsPrec :: Int -> ReadS AttributeDimension
Prelude.Read, Int -> AttributeDimension -> ShowS
[AttributeDimension] -> ShowS
AttributeDimension -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttributeDimension] -> ShowS
$cshowList :: [AttributeDimension] -> ShowS
show :: AttributeDimension -> String
$cshow :: AttributeDimension -> String
showsPrec :: Int -> AttributeDimension -> ShowS
$cshowsPrec :: Int -> AttributeDimension -> ShowS
Prelude.Show, forall x. Rep AttributeDimension x -> AttributeDimension
forall x. AttributeDimension -> Rep AttributeDimension x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttributeDimension x -> AttributeDimension
$cfrom :: forall x. AttributeDimension -> Rep AttributeDimension x
Prelude.Generic)

-- |
-- Create a value of 'AttributeDimension' 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:
--
-- 'attributeType', 'attributeDimension_attributeType' - The type of segment dimension to use. Valid values are:
--
-- INCLUSIVE - endpoints that have attributes matching the values are
-- included in the segment.
--
-- EXCLUSIVE - endpoints that have attributes matching the values are
-- excluded in the segment.
--
-- CONTAINS - endpoints that have attributes\' substrings match the values
-- are included in the segment.
--
-- BEFORE - endpoints with attributes read as ISO_INSTANT datetimes before
-- the value are included in the segment.
--
-- AFTER - endpoints with attributes read as ISO_INSTANT datetimes after
-- the value are included in the segment.
--
-- ON - endpoints with attributes read as ISO_INSTANT dates on the value
-- are included in the segment. Time is ignored in this comparison.
--
-- BETWEEN - endpoints with attributes read as ISO_INSTANT datetimes
-- between the values are included in the segment.
--
-- 'values', 'attributeDimension_values' - The criteria values to use for the segment dimension. Depending on the
-- value of the AttributeType property, endpoints are included or excluded
-- from the segment if their attribute values match the criteria values.
newAttributeDimension ::
  AttributeDimension
newAttributeDimension :: AttributeDimension
newAttributeDimension =
  AttributeDimension'
    { $sel:attributeType:AttributeDimension' :: Maybe AttributeType
attributeType =
        forall a. Maybe a
Prelude.Nothing,
      $sel:values:AttributeDimension' :: [Text]
values = forall a. Monoid a => a
Prelude.mempty
    }

-- | The type of segment dimension to use. Valid values are:
--
-- INCLUSIVE - endpoints that have attributes matching the values are
-- included in the segment.
--
-- EXCLUSIVE - endpoints that have attributes matching the values are
-- excluded in the segment.
--
-- CONTAINS - endpoints that have attributes\' substrings match the values
-- are included in the segment.
--
-- BEFORE - endpoints with attributes read as ISO_INSTANT datetimes before
-- the value are included in the segment.
--
-- AFTER - endpoints with attributes read as ISO_INSTANT datetimes after
-- the value are included in the segment.
--
-- ON - endpoints with attributes read as ISO_INSTANT dates on the value
-- are included in the segment. Time is ignored in this comparison.
--
-- BETWEEN - endpoints with attributes read as ISO_INSTANT datetimes
-- between the values are included in the segment.
attributeDimension_attributeType :: Lens.Lens' AttributeDimension (Prelude.Maybe AttributeType)
attributeDimension_attributeType :: Lens' AttributeDimension (Maybe AttributeType)
attributeDimension_attributeType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeDimension' {Maybe AttributeType
attributeType :: Maybe AttributeType
$sel:attributeType:AttributeDimension' :: AttributeDimension -> Maybe AttributeType
attributeType} -> Maybe AttributeType
attributeType) (\s :: AttributeDimension
s@AttributeDimension' {} Maybe AttributeType
a -> AttributeDimension
s {$sel:attributeType:AttributeDimension' :: Maybe AttributeType
attributeType = Maybe AttributeType
a} :: AttributeDimension)

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

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

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

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

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