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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(AttributeDimension -> AttributeDimension -> Bool)
-> (AttributeDimension -> AttributeDimension -> Bool)
-> Eq AttributeDimension
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]
(Int -> ReadS AttributeDimension)
-> ReadS [AttributeDimension]
-> ReadPrec AttributeDimension
-> ReadPrec [AttributeDimension]
-> Read 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
(Int -> AttributeDimension -> ShowS)
-> (AttributeDimension -> String)
-> ([AttributeDimension] -> ShowS)
-> Show AttributeDimension
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. AttributeDimension -> Rep AttributeDimension x)
-> (forall x. Rep AttributeDimension x -> AttributeDimension)
-> Generic AttributeDimension
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' :: Maybe AttributeType -> [Text] -> AttributeDimension
AttributeDimension'
    { $sel:attributeType:AttributeDimension' :: Maybe AttributeType
attributeType =
        Maybe AttributeType
forall a. Maybe a
Prelude.Nothing,
      $sel:values:AttributeDimension' :: [Text]
values = [Text]
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 :: (Maybe AttributeType -> f (Maybe AttributeType))
-> AttributeDimension -> f AttributeDimension
attributeDimension_attributeType = (AttributeDimension -> Maybe AttributeType)
-> (AttributeDimension
    -> Maybe AttributeType -> AttributeDimension)
-> Lens
     AttributeDimension
     AttributeDimension
     (Maybe AttributeType)
     (Maybe 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 :: ([Text] -> f [Text]) -> AttributeDimension -> f AttributeDimension
attributeDimension_values = (AttributeDimension -> [Text])
-> (AttributeDimension -> [Text] -> AttributeDimension)
-> Lens AttributeDimension AttributeDimension [Text] [Text]
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) (([Text] -> f [Text])
 -> AttributeDimension -> f AttributeDimension)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> AttributeDimension
-> f AttributeDimension
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 AttributeDimension where
  parseJSON :: Value -> Parser AttributeDimension
parseJSON =
    String
-> (Object -> Parser AttributeDimension)
-> Value
-> Parser AttributeDimension
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AttributeDimension"
      ( \Object
x ->
          Maybe AttributeType -> [Text] -> AttributeDimension
AttributeDimension'
            (Maybe AttributeType -> [Text] -> AttributeDimension)
-> Parser (Maybe AttributeType)
-> Parser ([Text] -> AttributeDimension)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe AttributeType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AttributeType")
            Parser ([Text] -> AttributeDimension)
-> Parser [Text] -> Parser AttributeDimension
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 AttributeDimension

instance Prelude.NFData AttributeDimension

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AttributeType" Text -> AttributeType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (AttributeType -> Pair) -> Maybe AttributeType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AttributeType
attributeType,
            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)
          ]
      )