{-# 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.ECS.Types.Scale
-- 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.ECS.Types.Scale where

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types.ScaleUnit
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A floating-point percentage of the desired number of tasks to place and
-- keep running in the task set.
--
-- /See:/ 'newScale' smart constructor.
data Scale = Scale'
  { -- | The value, specified as a percent total of a service\'s @desiredCount@,
    -- to scale the task set. Accepted values are numbers between 0 and 100.
    Scale -> Maybe Double
value :: Prelude.Maybe Prelude.Double,
    -- | The unit of measure for the scale value.
    Scale -> Maybe ScaleUnit
unit :: Prelude.Maybe ScaleUnit
  }
  deriving (Scale -> Scale -> Bool
(Scale -> Scale -> Bool) -> (Scale -> Scale -> Bool) -> Eq Scale
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Scale -> Scale -> Bool
$c/= :: Scale -> Scale -> Bool
== :: Scale -> Scale -> Bool
$c== :: Scale -> Scale -> Bool
Prelude.Eq, ReadPrec [Scale]
ReadPrec Scale
Int -> ReadS Scale
ReadS [Scale]
(Int -> ReadS Scale)
-> ReadS [Scale]
-> ReadPrec Scale
-> ReadPrec [Scale]
-> Read Scale
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Scale]
$creadListPrec :: ReadPrec [Scale]
readPrec :: ReadPrec Scale
$creadPrec :: ReadPrec Scale
readList :: ReadS [Scale]
$creadList :: ReadS [Scale]
readsPrec :: Int -> ReadS Scale
$creadsPrec :: Int -> ReadS Scale
Prelude.Read, Int -> Scale -> ShowS
[Scale] -> ShowS
Scale -> String
(Int -> Scale -> ShowS)
-> (Scale -> String) -> ([Scale] -> ShowS) -> Show Scale
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Scale] -> ShowS
$cshowList :: [Scale] -> ShowS
show :: Scale -> String
$cshow :: Scale -> String
showsPrec :: Int -> Scale -> ShowS
$cshowsPrec :: Int -> Scale -> ShowS
Prelude.Show, (forall x. Scale -> Rep Scale x)
-> (forall x. Rep Scale x -> Scale) -> Generic Scale
forall x. Rep Scale x -> Scale
forall x. Scale -> Rep Scale x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Scale x -> Scale
$cfrom :: forall x. Scale -> Rep Scale x
Prelude.Generic)

-- |
-- Create a value of 'Scale' 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:
--
-- 'value', 'scale_value' - The value, specified as a percent total of a service\'s @desiredCount@,
-- to scale the task set. Accepted values are numbers between 0 and 100.
--
-- 'unit', 'scale_unit' - The unit of measure for the scale value.
newScale ::
  Scale
newScale :: Scale
newScale =
  Scale' :: Maybe Double -> Maybe ScaleUnit -> Scale
Scale'
    { $sel:value:Scale' :: Maybe Double
value = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:unit:Scale' :: Maybe ScaleUnit
unit = Maybe ScaleUnit
forall a. Maybe a
Prelude.Nothing
    }

-- | The value, specified as a percent total of a service\'s @desiredCount@,
-- to scale the task set. Accepted values are numbers between 0 and 100.
scale_value :: Lens.Lens' Scale (Prelude.Maybe Prelude.Double)
scale_value :: (Maybe Double -> f (Maybe Double)) -> Scale -> f Scale
scale_value = (Scale -> Maybe Double)
-> (Scale -> Maybe Double -> Scale)
-> Lens Scale Scale (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Scale' {Maybe Double
value :: Maybe Double
$sel:value:Scale' :: Scale -> Maybe Double
value} -> Maybe Double
value) (\s :: Scale
s@Scale' {} Maybe Double
a -> Scale
s {$sel:value:Scale' :: Maybe Double
value = Maybe Double
a} :: Scale)

-- | The unit of measure for the scale value.
scale_unit :: Lens.Lens' Scale (Prelude.Maybe ScaleUnit)
scale_unit :: (Maybe ScaleUnit -> f (Maybe ScaleUnit)) -> Scale -> f Scale
scale_unit = (Scale -> Maybe ScaleUnit)
-> (Scale -> Maybe ScaleUnit -> Scale)
-> Lens Scale Scale (Maybe ScaleUnit) (Maybe ScaleUnit)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Scale' {Maybe ScaleUnit
unit :: Maybe ScaleUnit
$sel:unit:Scale' :: Scale -> Maybe ScaleUnit
unit} -> Maybe ScaleUnit
unit) (\s :: Scale
s@Scale' {} Maybe ScaleUnit
a -> Scale
s {$sel:unit:Scale' :: Maybe ScaleUnit
unit = Maybe ScaleUnit
a} :: Scale)

instance Core.FromJSON Scale where
  parseJSON :: Value -> Parser Scale
parseJSON =
    String -> (Object -> Parser Scale) -> Value -> Parser Scale
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Scale"
      ( \Object
x ->
          Maybe Double -> Maybe ScaleUnit -> Scale
Scale'
            (Maybe Double -> Maybe ScaleUnit -> Scale)
-> Parser (Maybe Double) -> Parser (Maybe ScaleUnit -> Scale)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"value") Parser (Maybe ScaleUnit -> Scale)
-> Parser (Maybe ScaleUnit) -> Parser Scale
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ScaleUnit)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"unit")
      )

instance Prelude.Hashable Scale

instance Prelude.NFData Scale

instance Core.ToJSON Scale where
  toJSON :: Scale -> Value
toJSON Scale' {Maybe Double
Maybe ScaleUnit
unit :: Maybe ScaleUnit
value :: Maybe Double
$sel:unit:Scale' :: Scale -> Maybe ScaleUnit
$sel:value:Scale' :: Scale -> Maybe Double
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"value" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
value,
            (Text
"unit" Text -> ScaleUnit -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ScaleUnit -> Pair) -> Maybe ScaleUnit -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ScaleUnit
unit
          ]
      )