{-# 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.Evidently.Types.Segment
-- 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.Evidently.Types.Segment where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | This structure contains information about one audience /segment/. You
-- can use segments in your experiments and launches to narrow the user
-- sessions used for experiment or launch to only the user sessions that
-- match one or more criteria.
--
-- /See:/ 'newSegment' smart constructor.
data Segment = Segment'
  { -- | The customer-created description for this segment.
    Segment -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The number of experiments that this segment is used in. This count
    -- includes all current experiments, not just those that are currently
    -- running.
    Segment -> Maybe Integer
experimentCount :: Prelude.Maybe Prelude.Integer,
    -- | The number of launches that this segment is used in. This count includes
    -- all current launches, not just those that are currently running.
    Segment -> Maybe Integer
launchCount :: Prelude.Maybe Prelude.Integer,
    -- | The list of tag keys and values associated with this launch.
    Segment -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The ARN of the segment.
    Segment -> Text
arn :: Prelude.Text,
    -- | The date and time that this segment was created.
    Segment -> POSIX
createdTime :: Data.POSIX,
    -- | The date and time that this segment was most recently updated.
    Segment -> POSIX
lastUpdatedTime :: Data.POSIX,
    -- | The name of the segment.
    Segment -> Text
name :: Prelude.Text,
    -- | The pattern that defines the attributes to use to evalute whether a user
    -- session will be in the segment. For more information about the pattern
    -- syntax, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Evidently-segments.html Segment rule pattern syntax>.
    Segment -> Text
pattern' :: Prelude.Text
  }
  deriving (Segment -> Segment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Segment -> Segment -> Bool
$c/= :: Segment -> Segment -> Bool
== :: Segment -> Segment -> Bool
$c== :: Segment -> Segment -> Bool
Prelude.Eq, ReadPrec [Segment]
ReadPrec Segment
Int -> ReadS Segment
ReadS [Segment]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Segment]
$creadListPrec :: ReadPrec [Segment]
readPrec :: ReadPrec Segment
$creadPrec :: ReadPrec Segment
readList :: ReadS [Segment]
$creadList :: ReadS [Segment]
readsPrec :: Int -> ReadS Segment
$creadsPrec :: Int -> ReadS Segment
Prelude.Read, Int -> Segment -> ShowS
[Segment] -> ShowS
Segment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Segment] -> ShowS
$cshowList :: [Segment] -> ShowS
show :: Segment -> String
$cshow :: Segment -> String
showsPrec :: Int -> Segment -> ShowS
$cshowsPrec :: Int -> Segment -> ShowS
Prelude.Show, forall x. Rep Segment x -> Segment
forall x. Segment -> Rep Segment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Segment x -> Segment
$cfrom :: forall x. Segment -> Rep Segment x
Prelude.Generic)

-- |
-- Create a value of 'Segment' 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:
--
-- 'description', 'segment_description' - The customer-created description for this segment.
--
-- 'experimentCount', 'segment_experimentCount' - The number of experiments that this segment is used in. This count
-- includes all current experiments, not just those that are currently
-- running.
--
-- 'launchCount', 'segment_launchCount' - The number of launches that this segment is used in. This count includes
-- all current launches, not just those that are currently running.
--
-- 'tags', 'segment_tags' - The list of tag keys and values associated with this launch.
--
-- 'arn', 'segment_arn' - The ARN of the segment.
--
-- 'createdTime', 'segment_createdTime' - The date and time that this segment was created.
--
-- 'lastUpdatedTime', 'segment_lastUpdatedTime' - The date and time that this segment was most recently updated.
--
-- 'name', 'segment_name' - The name of the segment.
--
-- 'pattern'', 'segment_pattern' - The pattern that defines the attributes to use to evalute whether a user
-- session will be in the segment. For more information about the pattern
-- syntax, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Evidently-segments.html Segment rule pattern syntax>.
newSegment ::
  -- | 'arn'
  Prelude.Text ->
  -- | 'createdTime'
  Prelude.UTCTime ->
  -- | 'lastUpdatedTime'
  Prelude.UTCTime ->
  -- | 'name'
  Prelude.Text ->
  -- | 'pattern''
  Prelude.Text ->
  Segment
newSegment :: Text -> UTCTime -> UTCTime -> Text -> Text -> Segment
newSegment
  Text
pArn_
  UTCTime
pCreatedTime_
  UTCTime
pLastUpdatedTime_
  Text
pName_
  Text
pPattern_ =
    Segment'
      { $sel:description:Segment' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
        $sel:experimentCount:Segment' :: Maybe Integer
experimentCount = forall a. Maybe a
Prelude.Nothing,
        $sel:launchCount:Segment' :: Maybe Integer
launchCount = forall a. Maybe a
Prelude.Nothing,
        $sel:tags:Segment' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
        $sel:arn:Segment' :: Text
arn = Text
pArn_,
        $sel:createdTime:Segment' :: POSIX
createdTime = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pCreatedTime_,
        $sel:lastUpdatedTime:Segment' :: POSIX
lastUpdatedTime =
          forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pLastUpdatedTime_,
        $sel:name:Segment' :: Text
name = Text
pName_,
        $sel:pattern':Segment' :: Text
pattern' = Text
pPattern_
      }

-- | The customer-created description for this segment.
segment_description :: Lens.Lens' Segment (Prelude.Maybe Prelude.Text)
segment_description :: Lens' Segment (Maybe Text)
segment_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Maybe Text
description :: Maybe Text
$sel:description:Segment' :: Segment -> Maybe Text
description} -> Maybe Text
description) (\s :: Segment
s@Segment' {} Maybe Text
a -> Segment
s {$sel:description:Segment' :: Maybe Text
description = Maybe Text
a} :: Segment)

-- | The number of experiments that this segment is used in. This count
-- includes all current experiments, not just those that are currently
-- running.
segment_experimentCount :: Lens.Lens' Segment (Prelude.Maybe Prelude.Integer)
segment_experimentCount :: Lens' Segment (Maybe Integer)
segment_experimentCount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Maybe Integer
experimentCount :: Maybe Integer
$sel:experimentCount:Segment' :: Segment -> Maybe Integer
experimentCount} -> Maybe Integer
experimentCount) (\s :: Segment
s@Segment' {} Maybe Integer
a -> Segment
s {$sel:experimentCount:Segment' :: Maybe Integer
experimentCount = Maybe Integer
a} :: Segment)

-- | The number of launches that this segment is used in. This count includes
-- all current launches, not just those that are currently running.
segment_launchCount :: Lens.Lens' Segment (Prelude.Maybe Prelude.Integer)
segment_launchCount :: Lens' Segment (Maybe Integer)
segment_launchCount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Maybe Integer
launchCount :: Maybe Integer
$sel:launchCount:Segment' :: Segment -> Maybe Integer
launchCount} -> Maybe Integer
launchCount) (\s :: Segment
s@Segment' {} Maybe Integer
a -> Segment
s {$sel:launchCount:Segment' :: Maybe Integer
launchCount = Maybe Integer
a} :: Segment)

-- | The list of tag keys and values associated with this launch.
segment_tags :: Lens.Lens' Segment (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
segment_tags :: Lens' Segment (Maybe (HashMap Text Text))
segment_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:Segment' :: Segment -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: Segment
s@Segment' {} Maybe (HashMap Text Text)
a -> Segment
s {$sel:tags:Segment' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: Segment) 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 ARN of the segment.
segment_arn :: Lens.Lens' Segment Prelude.Text
segment_arn :: Lens' Segment Text
segment_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Text
arn :: Text
$sel:arn:Segment' :: Segment -> Text
arn} -> Text
arn) (\s :: Segment
s@Segment' {} Text
a -> Segment
s {$sel:arn:Segment' :: Text
arn = Text
a} :: Segment)

-- | The date and time that this segment was created.
segment_createdTime :: Lens.Lens' Segment Prelude.UTCTime
segment_createdTime :: Lens' Segment UTCTime
segment_createdTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {POSIX
createdTime :: POSIX
$sel:createdTime:Segment' :: Segment -> POSIX
createdTime} -> POSIX
createdTime) (\s :: Segment
s@Segment' {} POSIX
a -> Segment
s {$sel:createdTime:Segment' :: POSIX
createdTime = POSIX
a} :: Segment) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The date and time that this segment was most recently updated.
segment_lastUpdatedTime :: Lens.Lens' Segment Prelude.UTCTime
segment_lastUpdatedTime :: Lens' Segment UTCTime
segment_lastUpdatedTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {POSIX
lastUpdatedTime :: POSIX
$sel:lastUpdatedTime:Segment' :: Segment -> POSIX
lastUpdatedTime} -> POSIX
lastUpdatedTime) (\s :: Segment
s@Segment' {} POSIX
a -> Segment
s {$sel:lastUpdatedTime:Segment' :: POSIX
lastUpdatedTime = POSIX
a} :: Segment) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The name of the segment.
segment_name :: Lens.Lens' Segment Prelude.Text
segment_name :: Lens' Segment Text
segment_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Text
name :: Text
$sel:name:Segment' :: Segment -> Text
name} -> Text
name) (\s :: Segment
s@Segment' {} Text
a -> Segment
s {$sel:name:Segment' :: Text
name = Text
a} :: Segment)

-- | The pattern that defines the attributes to use to evalute whether a user
-- session will be in the segment. For more information about the pattern
-- syntax, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Evidently-segments.html Segment rule pattern syntax>.
segment_pattern :: Lens.Lens' Segment Prelude.Text
segment_pattern :: Lens' Segment Text
segment_pattern = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Segment' {Text
pattern' :: Text
$sel:pattern':Segment' :: Segment -> Text
pattern'} -> Text
pattern') (\s :: Segment
s@Segment' {} Text
a -> Segment
s {$sel:pattern':Segment' :: Text
pattern' = Text
a} :: Segment)

instance Data.FromJSON Segment where
  parseJSON :: Value -> Parser Segment
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Segment"
      ( \Object
x ->
          Maybe Text
-> Maybe Integer
-> Maybe Integer
-> Maybe (HashMap Text Text)
-> Text
-> POSIX
-> POSIX
-> Text
-> Text
-> Segment
Segment'
            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
"description")
            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
"experimentCount")
            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
"launchCount")
            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
"tags" 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
"arn")
            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
"createdTime")
            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
"lastUpdatedTime")
            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")
            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
"pattern")
      )

instance Prelude.Hashable Segment where
  hashWithSalt :: Int -> Segment -> Int
hashWithSalt Int
_salt Segment' {Maybe Integer
Maybe Text
Maybe (HashMap Text Text)
Text
POSIX
pattern' :: Text
name :: Text
lastUpdatedTime :: POSIX
createdTime :: POSIX
arn :: Text
tags :: Maybe (HashMap Text Text)
launchCount :: Maybe Integer
experimentCount :: Maybe Integer
description :: Maybe Text
$sel:pattern':Segment' :: Segment -> Text
$sel:name:Segment' :: Segment -> Text
$sel:lastUpdatedTime:Segment' :: Segment -> POSIX
$sel:createdTime:Segment' :: Segment -> POSIX
$sel:arn:Segment' :: Segment -> Text
$sel:tags:Segment' :: Segment -> Maybe (HashMap Text Text)
$sel:launchCount:Segment' :: Segment -> Maybe Integer
$sel:experimentCount:Segment' :: Segment -> Maybe Integer
$sel:description:Segment' :: Segment -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
experimentCount
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
launchCount
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` POSIX
createdTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` POSIX
lastUpdatedTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
pattern'

instance Prelude.NFData Segment where
  rnf :: Segment -> ()
rnf Segment' {Maybe Integer
Maybe Text
Maybe (HashMap Text Text)
Text
POSIX
pattern' :: Text
name :: Text
lastUpdatedTime :: POSIX
createdTime :: POSIX
arn :: Text
tags :: Maybe (HashMap Text Text)
launchCount :: Maybe Integer
experimentCount :: Maybe Integer
description :: Maybe Text
$sel:pattern':Segment' :: Segment -> Text
$sel:name:Segment' :: Segment -> Text
$sel:lastUpdatedTime:Segment' :: Segment -> POSIX
$sel:createdTime:Segment' :: Segment -> POSIX
$sel:arn:Segment' :: Segment -> Text
$sel:tags:Segment' :: Segment -> Maybe (HashMap Text Text)
$sel:launchCount:Segment' :: Segment -> Maybe Integer
$sel:experimentCount:Segment' :: Segment -> Maybe Integer
$sel:description:Segment' :: Segment -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
experimentCount
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
launchCount
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf POSIX
createdTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf POSIX
lastUpdatedTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
pattern'