{-# 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.Batch.Types.ShareAttributes
-- 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.Batch.Types.ShareAttributes 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

-- | Specifies the weights for the fair share identifiers for the fair share
-- policy. Fair share identifiers that aren\'t included have a default
-- weight of @1.0@.
--
-- /See:/ 'newShareAttributes' smart constructor.
data ShareAttributes = ShareAttributes'
  { -- | The weight factor for the fair share identifier. The default value is
    -- 1.0. A lower value has a higher priority for compute resources. For
    -- example, jobs that use a share identifier with a weight factor of 0.125
    -- (1\/8) get 8 times the compute resources of jobs that use a share
    -- identifier with a weight factor of 1.
    --
    -- The smallest supported value is 0.0001, and the largest supported value
    -- is 999.9999.
    ShareAttributes -> Maybe Double
weightFactor :: Prelude.Maybe Prelude.Double,
    -- | A fair share identifier or fair share identifier prefix. If the string
    -- ends with an asterisk (*), this entry specifies the weight factor to use
    -- for fair share identifiers that start with that prefix. The list of fair
    -- share identifiers in a fair share policy can\'t overlap. For example,
    -- you can\'t have one that specifies a @shareIdentifier@ of @UserA*@ and
    -- another that specifies a @shareIdentifier@ of @UserA-1@.
    --
    -- There can be no more than 500 fair share identifiers active in a job
    -- queue.
    --
    -- The string is limited to 255 alphanumeric characters, and can be
    -- followed by an asterisk (*).
    ShareAttributes -> Text
shareIdentifier :: Prelude.Text
  }
  deriving (ShareAttributes -> ShareAttributes -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ShareAttributes -> ShareAttributes -> Bool
$c/= :: ShareAttributes -> ShareAttributes -> Bool
== :: ShareAttributes -> ShareAttributes -> Bool
$c== :: ShareAttributes -> ShareAttributes -> Bool
Prelude.Eq, ReadPrec [ShareAttributes]
ReadPrec ShareAttributes
Int -> ReadS ShareAttributes
ReadS [ShareAttributes]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ShareAttributes]
$creadListPrec :: ReadPrec [ShareAttributes]
readPrec :: ReadPrec ShareAttributes
$creadPrec :: ReadPrec ShareAttributes
readList :: ReadS [ShareAttributes]
$creadList :: ReadS [ShareAttributes]
readsPrec :: Int -> ReadS ShareAttributes
$creadsPrec :: Int -> ReadS ShareAttributes
Prelude.Read, Int -> ShareAttributes -> ShowS
[ShareAttributes] -> ShowS
ShareAttributes -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShareAttributes] -> ShowS
$cshowList :: [ShareAttributes] -> ShowS
show :: ShareAttributes -> String
$cshow :: ShareAttributes -> String
showsPrec :: Int -> ShareAttributes -> ShowS
$cshowsPrec :: Int -> ShareAttributes -> ShowS
Prelude.Show, forall x. Rep ShareAttributes x -> ShareAttributes
forall x. ShareAttributes -> Rep ShareAttributes x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ShareAttributes x -> ShareAttributes
$cfrom :: forall x. ShareAttributes -> Rep ShareAttributes x
Prelude.Generic)

-- |
-- Create a value of 'ShareAttributes' 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:
--
-- 'weightFactor', 'shareAttributes_weightFactor' - The weight factor for the fair share identifier. The default value is
-- 1.0. A lower value has a higher priority for compute resources. For
-- example, jobs that use a share identifier with a weight factor of 0.125
-- (1\/8) get 8 times the compute resources of jobs that use a share
-- identifier with a weight factor of 1.
--
-- The smallest supported value is 0.0001, and the largest supported value
-- is 999.9999.
--
-- 'shareIdentifier', 'shareAttributes_shareIdentifier' - A fair share identifier or fair share identifier prefix. If the string
-- ends with an asterisk (*), this entry specifies the weight factor to use
-- for fair share identifiers that start with that prefix. The list of fair
-- share identifiers in a fair share policy can\'t overlap. For example,
-- you can\'t have one that specifies a @shareIdentifier@ of @UserA*@ and
-- another that specifies a @shareIdentifier@ of @UserA-1@.
--
-- There can be no more than 500 fair share identifiers active in a job
-- queue.
--
-- The string is limited to 255 alphanumeric characters, and can be
-- followed by an asterisk (*).
newShareAttributes ::
  -- | 'shareIdentifier'
  Prelude.Text ->
  ShareAttributes
newShareAttributes :: Text -> ShareAttributes
newShareAttributes Text
pShareIdentifier_ =
  ShareAttributes'
    { $sel:weightFactor:ShareAttributes' :: Maybe Double
weightFactor = forall a. Maybe a
Prelude.Nothing,
      $sel:shareIdentifier:ShareAttributes' :: Text
shareIdentifier = Text
pShareIdentifier_
    }

-- | The weight factor for the fair share identifier. The default value is
-- 1.0. A lower value has a higher priority for compute resources. For
-- example, jobs that use a share identifier with a weight factor of 0.125
-- (1\/8) get 8 times the compute resources of jobs that use a share
-- identifier with a weight factor of 1.
--
-- The smallest supported value is 0.0001, and the largest supported value
-- is 999.9999.
shareAttributes_weightFactor :: Lens.Lens' ShareAttributes (Prelude.Maybe Prelude.Double)
shareAttributes_weightFactor :: Lens' ShareAttributes (Maybe Double)
shareAttributes_weightFactor = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShareAttributes' {Maybe Double
weightFactor :: Maybe Double
$sel:weightFactor:ShareAttributes' :: ShareAttributes -> Maybe Double
weightFactor} -> Maybe Double
weightFactor) (\s :: ShareAttributes
s@ShareAttributes' {} Maybe Double
a -> ShareAttributes
s {$sel:weightFactor:ShareAttributes' :: Maybe Double
weightFactor = Maybe Double
a} :: ShareAttributes)

-- | A fair share identifier or fair share identifier prefix. If the string
-- ends with an asterisk (*), this entry specifies the weight factor to use
-- for fair share identifiers that start with that prefix. The list of fair
-- share identifiers in a fair share policy can\'t overlap. For example,
-- you can\'t have one that specifies a @shareIdentifier@ of @UserA*@ and
-- another that specifies a @shareIdentifier@ of @UserA-1@.
--
-- There can be no more than 500 fair share identifiers active in a job
-- queue.
--
-- The string is limited to 255 alphanumeric characters, and can be
-- followed by an asterisk (*).
shareAttributes_shareIdentifier :: Lens.Lens' ShareAttributes Prelude.Text
shareAttributes_shareIdentifier :: Lens' ShareAttributes Text
shareAttributes_shareIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShareAttributes' {Text
shareIdentifier :: Text
$sel:shareIdentifier:ShareAttributes' :: ShareAttributes -> Text
shareIdentifier} -> Text
shareIdentifier) (\s :: ShareAttributes
s@ShareAttributes' {} Text
a -> ShareAttributes
s {$sel:shareIdentifier:ShareAttributes' :: Text
shareIdentifier = Text
a} :: ShareAttributes)

instance Data.FromJSON ShareAttributes where
  parseJSON :: Value -> Parser ShareAttributes
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ShareAttributes"
      ( \Object
x ->
          Maybe Double -> Text -> ShareAttributes
ShareAttributes'
            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
"weightFactor")
            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
"shareIdentifier")
      )

instance Prelude.Hashable ShareAttributes where
  hashWithSalt :: Int -> ShareAttributes -> Int
hashWithSalt Int
_salt ShareAttributes' {Maybe Double
Text
shareIdentifier :: Text
weightFactor :: Maybe Double
$sel:shareIdentifier:ShareAttributes' :: ShareAttributes -> Text
$sel:weightFactor:ShareAttributes' :: ShareAttributes -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
weightFactor
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
shareIdentifier

instance Prelude.NFData ShareAttributes where
  rnf :: ShareAttributes -> ()
rnf ShareAttributes' {Maybe Double
Text
shareIdentifier :: Text
weightFactor :: Maybe Double
$sel:shareIdentifier:ShareAttributes' :: ShareAttributes -> Text
$sel:weightFactor:ShareAttributes' :: ShareAttributes -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
weightFactor
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
shareIdentifier

instance Data.ToJSON ShareAttributes where
  toJSON :: ShareAttributes -> Value
toJSON ShareAttributes' {Maybe Double
Text
shareIdentifier :: Text
weightFactor :: Maybe Double
$sel:shareIdentifier:ShareAttributes' :: ShareAttributes -> Text
$sel:weightFactor:ShareAttributes' :: ShareAttributes -> Maybe Double
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"weightFactor" 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 Double
weightFactor,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"shareIdentifier" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
shareIdentifier)
          ]
      )