{-# 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.TrafficPattern
-- 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.TrafficPattern 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
import Amazonka.SageMaker.Types.Phase
import Amazonka.SageMaker.Types.TrafficType

-- | Defines the traffic pattern of the load test.
--
-- /See:/ 'newTrafficPattern' smart constructor.
data TrafficPattern = TrafficPattern'
  { -- | Defines the phases traffic specification.
    TrafficPattern -> Maybe (NonEmpty Phase)
phases :: Prelude.Maybe (Prelude.NonEmpty Phase),
    -- | Defines the traffic patterns.
    TrafficPattern -> Maybe TrafficType
trafficType :: Prelude.Maybe TrafficType
  }
  deriving (TrafficPattern -> TrafficPattern -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TrafficPattern -> TrafficPattern -> Bool
$c/= :: TrafficPattern -> TrafficPattern -> Bool
== :: TrafficPattern -> TrafficPattern -> Bool
$c== :: TrafficPattern -> TrafficPattern -> Bool
Prelude.Eq, ReadPrec [TrafficPattern]
ReadPrec TrafficPattern
Int -> ReadS TrafficPattern
ReadS [TrafficPattern]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TrafficPattern]
$creadListPrec :: ReadPrec [TrafficPattern]
readPrec :: ReadPrec TrafficPattern
$creadPrec :: ReadPrec TrafficPattern
readList :: ReadS [TrafficPattern]
$creadList :: ReadS [TrafficPattern]
readsPrec :: Int -> ReadS TrafficPattern
$creadsPrec :: Int -> ReadS TrafficPattern
Prelude.Read, Int -> TrafficPattern -> ShowS
[TrafficPattern] -> ShowS
TrafficPattern -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TrafficPattern] -> ShowS
$cshowList :: [TrafficPattern] -> ShowS
show :: TrafficPattern -> String
$cshow :: TrafficPattern -> String
showsPrec :: Int -> TrafficPattern -> ShowS
$cshowsPrec :: Int -> TrafficPattern -> ShowS
Prelude.Show, forall x. Rep TrafficPattern x -> TrafficPattern
forall x. TrafficPattern -> Rep TrafficPattern x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TrafficPattern x -> TrafficPattern
$cfrom :: forall x. TrafficPattern -> Rep TrafficPattern x
Prelude.Generic)

-- |
-- Create a value of 'TrafficPattern' 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:
--
-- 'phases', 'trafficPattern_phases' - Defines the phases traffic specification.
--
-- 'trafficType', 'trafficPattern_trafficType' - Defines the traffic patterns.
newTrafficPattern ::
  TrafficPattern
newTrafficPattern :: TrafficPattern
newTrafficPattern =
  TrafficPattern'
    { $sel:phases:TrafficPattern' :: Maybe (NonEmpty Phase)
phases = forall a. Maybe a
Prelude.Nothing,
      $sel:trafficType:TrafficPattern' :: Maybe TrafficType
trafficType = forall a. Maybe a
Prelude.Nothing
    }

-- | Defines the phases traffic specification.
trafficPattern_phases :: Lens.Lens' TrafficPattern (Prelude.Maybe (Prelude.NonEmpty Phase))
trafficPattern_phases :: Lens' TrafficPattern (Maybe (NonEmpty Phase))
trafficPattern_phases = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrafficPattern' {Maybe (NonEmpty Phase)
phases :: Maybe (NonEmpty Phase)
$sel:phases:TrafficPattern' :: TrafficPattern -> Maybe (NonEmpty Phase)
phases} -> Maybe (NonEmpty Phase)
phases) (\s :: TrafficPattern
s@TrafficPattern' {} Maybe (NonEmpty Phase)
a -> TrafficPattern
s {$sel:phases:TrafficPattern' :: Maybe (NonEmpty Phase)
phases = Maybe (NonEmpty Phase)
a} :: TrafficPattern) 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

-- | Defines the traffic patterns.
trafficPattern_trafficType :: Lens.Lens' TrafficPattern (Prelude.Maybe TrafficType)
trafficPattern_trafficType :: Lens' TrafficPattern (Maybe TrafficType)
trafficPattern_trafficType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrafficPattern' {Maybe TrafficType
trafficType :: Maybe TrafficType
$sel:trafficType:TrafficPattern' :: TrafficPattern -> Maybe TrafficType
trafficType} -> Maybe TrafficType
trafficType) (\s :: TrafficPattern
s@TrafficPattern' {} Maybe TrafficType
a -> TrafficPattern
s {$sel:trafficType:TrafficPattern' :: Maybe TrafficType
trafficType = Maybe TrafficType
a} :: TrafficPattern)

instance Data.FromJSON TrafficPattern where
  parseJSON :: Value -> Parser TrafficPattern
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TrafficPattern"
      ( \Object
x ->
          Maybe (NonEmpty Phase) -> Maybe TrafficType -> TrafficPattern
TrafficPattern'
            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
"Phases")
            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
"TrafficType")
      )

instance Prelude.Hashable TrafficPattern where
  hashWithSalt :: Int -> TrafficPattern -> Int
hashWithSalt Int
_salt TrafficPattern' {Maybe (NonEmpty Phase)
Maybe TrafficType
trafficType :: Maybe TrafficType
phases :: Maybe (NonEmpty Phase)
$sel:trafficType:TrafficPattern' :: TrafficPattern -> Maybe TrafficType
$sel:phases:TrafficPattern' :: TrafficPattern -> Maybe (NonEmpty Phase)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Phase)
phases
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe TrafficType
trafficType

instance Prelude.NFData TrafficPattern where
  rnf :: TrafficPattern -> ()
rnf TrafficPattern' {Maybe (NonEmpty Phase)
Maybe TrafficType
trafficType :: Maybe TrafficType
phases :: Maybe (NonEmpty Phase)
$sel:trafficType:TrafficPattern' :: TrafficPattern -> Maybe TrafficType
$sel:phases:TrafficPattern' :: TrafficPattern -> Maybe (NonEmpty Phase)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Phase)
phases
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe TrafficType
trafficType

instance Data.ToJSON TrafficPattern where
  toJSON :: TrafficPattern -> Value
toJSON TrafficPattern' {Maybe (NonEmpty Phase)
Maybe TrafficType
trafficType :: Maybe TrafficType
phases :: Maybe (NonEmpty Phase)
$sel:trafficType:TrafficPattern' :: TrafficPattern -> Maybe TrafficType
$sel:phases:TrafficPattern' :: TrafficPattern -> Maybe (NonEmpty Phase)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Phases" 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 (NonEmpty Phase)
phases,
            (Key
"TrafficType" 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 TrafficType
trafficType
          ]
      )