{-# 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.SageMaker.Types.Phase
-- 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.SageMaker.Types.Phase 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

-- | Defines the traffic pattern.
--
-- /See:/ 'newPhase' smart constructor.
data Phase = Phase'
  { -- | Specifies how long traffic phase should be.
    Phase -> Maybe Natural
durationInSeconds :: Prelude.Maybe Prelude.Natural,
    -- | Specifies how many concurrent users to start with.
    Phase -> Maybe Natural
initialNumberOfUsers :: Prelude.Maybe Prelude.Natural,
    -- | Specified how many new users to spawn in a minute.
    Phase -> Maybe Natural
spawnRate :: Prelude.Maybe Prelude.Natural
  }
  deriving (Phase -> Phase -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Phase -> Phase -> Bool
$c/= :: Phase -> Phase -> Bool
== :: Phase -> Phase -> Bool
$c== :: Phase -> Phase -> Bool
Prelude.Eq, ReadPrec [Phase]
ReadPrec Phase
Int -> ReadS Phase
ReadS [Phase]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Phase]
$creadListPrec :: ReadPrec [Phase]
readPrec :: ReadPrec Phase
$creadPrec :: ReadPrec Phase
readList :: ReadS [Phase]
$creadList :: ReadS [Phase]
readsPrec :: Int -> ReadS Phase
$creadsPrec :: Int -> ReadS Phase
Prelude.Read, Int -> Phase -> ShowS
[Phase] -> ShowS
Phase -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Phase] -> ShowS
$cshowList :: [Phase] -> ShowS
show :: Phase -> String
$cshow :: Phase -> String
showsPrec :: Int -> Phase -> ShowS
$cshowsPrec :: Int -> Phase -> ShowS
Prelude.Show, forall x. Rep Phase x -> Phase
forall x. Phase -> Rep Phase x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Phase x -> Phase
$cfrom :: forall x. Phase -> Rep Phase x
Prelude.Generic)

-- |
-- Create a value of 'Phase' 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:
--
-- 'durationInSeconds', 'phase_durationInSeconds' - Specifies how long traffic phase should be.
--
-- 'initialNumberOfUsers', 'phase_initialNumberOfUsers' - Specifies how many concurrent users to start with.
--
-- 'spawnRate', 'phase_spawnRate' - Specified how many new users to spawn in a minute.
newPhase ::
  Phase
newPhase :: Phase
newPhase =
  Phase'
    { $sel:durationInSeconds:Phase' :: Maybe Natural
durationInSeconds = forall a. Maybe a
Prelude.Nothing,
      $sel:initialNumberOfUsers:Phase' :: Maybe Natural
initialNumberOfUsers = forall a. Maybe a
Prelude.Nothing,
      $sel:spawnRate:Phase' :: Maybe Natural
spawnRate = forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies how long traffic phase should be.
phase_durationInSeconds :: Lens.Lens' Phase (Prelude.Maybe Prelude.Natural)
phase_durationInSeconds :: Lens' Phase (Maybe Natural)
phase_durationInSeconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Phase' {Maybe Natural
durationInSeconds :: Maybe Natural
$sel:durationInSeconds:Phase' :: Phase -> Maybe Natural
durationInSeconds} -> Maybe Natural
durationInSeconds) (\s :: Phase
s@Phase' {} Maybe Natural
a -> Phase
s {$sel:durationInSeconds:Phase' :: Maybe Natural
durationInSeconds = Maybe Natural
a} :: Phase)

-- | Specifies how many concurrent users to start with.
phase_initialNumberOfUsers :: Lens.Lens' Phase (Prelude.Maybe Prelude.Natural)
phase_initialNumberOfUsers :: Lens' Phase (Maybe Natural)
phase_initialNumberOfUsers = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Phase' {Maybe Natural
initialNumberOfUsers :: Maybe Natural
$sel:initialNumberOfUsers:Phase' :: Phase -> Maybe Natural
initialNumberOfUsers} -> Maybe Natural
initialNumberOfUsers) (\s :: Phase
s@Phase' {} Maybe Natural
a -> Phase
s {$sel:initialNumberOfUsers:Phase' :: Maybe Natural
initialNumberOfUsers = Maybe Natural
a} :: Phase)

-- | Specified how many new users to spawn in a minute.
phase_spawnRate :: Lens.Lens' Phase (Prelude.Maybe Prelude.Natural)
phase_spawnRate :: Lens' Phase (Maybe Natural)
phase_spawnRate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Phase' {Maybe Natural
spawnRate :: Maybe Natural
$sel:spawnRate:Phase' :: Phase -> Maybe Natural
spawnRate} -> Maybe Natural
spawnRate) (\s :: Phase
s@Phase' {} Maybe Natural
a -> Phase
s {$sel:spawnRate:Phase' :: Maybe Natural
spawnRate = Maybe Natural
a} :: Phase)

instance Data.FromJSON Phase where
  parseJSON :: Value -> Parser Phase
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Phase"
      ( \Object
x ->
          Maybe Natural -> Maybe Natural -> Maybe Natural -> Phase
Phase'
            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
"DurationInSeconds")
            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
"InitialNumberOfUsers")
            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
"SpawnRate")
      )

instance Prelude.Hashable Phase where
  hashWithSalt :: Int -> Phase -> Int
hashWithSalt Int
_salt Phase' {Maybe Natural
spawnRate :: Maybe Natural
initialNumberOfUsers :: Maybe Natural
durationInSeconds :: Maybe Natural
$sel:spawnRate:Phase' :: Phase -> Maybe Natural
$sel:initialNumberOfUsers:Phase' :: Phase -> Maybe Natural
$sel:durationInSeconds:Phase' :: Phase -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
durationInSeconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
initialNumberOfUsers
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
spawnRate

instance Prelude.NFData Phase where
  rnf :: Phase -> ()
rnf Phase' {Maybe Natural
spawnRate :: Maybe Natural
initialNumberOfUsers :: Maybe Natural
durationInSeconds :: Maybe Natural
$sel:spawnRate:Phase' :: Phase -> Maybe Natural
$sel:initialNumberOfUsers:Phase' :: Phase -> Maybe Natural
$sel:durationInSeconds:Phase' :: Phase -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
durationInSeconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
initialNumberOfUsers
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
spawnRate

instance Data.ToJSON Phase where
  toJSON :: Phase -> Value
toJSON Phase' {Maybe Natural
spawnRate :: Maybe Natural
initialNumberOfUsers :: Maybe Natural
durationInSeconds :: Maybe Natural
$sel:spawnRate:Phase' :: Phase -> Maybe Natural
$sel:initialNumberOfUsers:Phase' :: Phase -> Maybe Natural
$sel:durationInSeconds:Phase' :: Phase -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DurationInSeconds" 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 Natural
durationInSeconds,
            (Key
"InitialNumberOfUsers" 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 Natural
initialNumberOfUsers,
            (Key
"SpawnRate" 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 Natural
spawnRate
          ]
      )