{-# 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.GameLift.Types.ResourceCreationLimitPolicy
-- 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.GameLift.Types.ResourceCreationLimitPolicy where

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

-- | A policy that puts limits on the number of game sessions that a player
-- can create within a specified span of time. With this policy, you can
-- control players\' ability to consume available resources.
--
-- The policy is evaluated when a player tries to create a new game
-- session. On receiving a @CreateGameSession@ request, GameLift checks
-- that the player (identified by @CreatorId@) has created fewer than game
-- session limit in the specified time period.
--
-- The resource creation limit policy is included in FleetAttributes.
--
-- /See:/ 'newResourceCreationLimitPolicy' smart constructor.
data ResourceCreationLimitPolicy = ResourceCreationLimitPolicy'
  { -- | The maximum number of game sessions that an individual can create during
    -- the policy period.
    ResourceCreationLimitPolicy -> Maybe Natural
newGameSessionsPerCreator' :: Prelude.Maybe Prelude.Natural,
    -- | The time span used in evaluating the resource creation limit policy.
    ResourceCreationLimitPolicy -> Maybe Natural
policyPeriodInMinutes :: Prelude.Maybe Prelude.Natural
  }
  deriving (ResourceCreationLimitPolicy -> ResourceCreationLimitPolicy -> Bool
(ResourceCreationLimitPolicy
 -> ResourceCreationLimitPolicy -> Bool)
-> (ResourceCreationLimitPolicy
    -> ResourceCreationLimitPolicy -> Bool)
-> Eq ResourceCreationLimitPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceCreationLimitPolicy -> ResourceCreationLimitPolicy -> Bool
$c/= :: ResourceCreationLimitPolicy -> ResourceCreationLimitPolicy -> Bool
== :: ResourceCreationLimitPolicy -> ResourceCreationLimitPolicy -> Bool
$c== :: ResourceCreationLimitPolicy -> ResourceCreationLimitPolicy -> Bool
Prelude.Eq, ReadPrec [ResourceCreationLimitPolicy]
ReadPrec ResourceCreationLimitPolicy
Int -> ReadS ResourceCreationLimitPolicy
ReadS [ResourceCreationLimitPolicy]
(Int -> ReadS ResourceCreationLimitPolicy)
-> ReadS [ResourceCreationLimitPolicy]
-> ReadPrec ResourceCreationLimitPolicy
-> ReadPrec [ResourceCreationLimitPolicy]
-> Read ResourceCreationLimitPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceCreationLimitPolicy]
$creadListPrec :: ReadPrec [ResourceCreationLimitPolicy]
readPrec :: ReadPrec ResourceCreationLimitPolicy
$creadPrec :: ReadPrec ResourceCreationLimitPolicy
readList :: ReadS [ResourceCreationLimitPolicy]
$creadList :: ReadS [ResourceCreationLimitPolicy]
readsPrec :: Int -> ReadS ResourceCreationLimitPolicy
$creadsPrec :: Int -> ReadS ResourceCreationLimitPolicy
Prelude.Read, Int -> ResourceCreationLimitPolicy -> ShowS
[ResourceCreationLimitPolicy] -> ShowS
ResourceCreationLimitPolicy -> String
(Int -> ResourceCreationLimitPolicy -> ShowS)
-> (ResourceCreationLimitPolicy -> String)
-> ([ResourceCreationLimitPolicy] -> ShowS)
-> Show ResourceCreationLimitPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceCreationLimitPolicy] -> ShowS
$cshowList :: [ResourceCreationLimitPolicy] -> ShowS
show :: ResourceCreationLimitPolicy -> String
$cshow :: ResourceCreationLimitPolicy -> String
showsPrec :: Int -> ResourceCreationLimitPolicy -> ShowS
$cshowsPrec :: Int -> ResourceCreationLimitPolicy -> ShowS
Prelude.Show, (forall x.
 ResourceCreationLimitPolicy -> Rep ResourceCreationLimitPolicy x)
-> (forall x.
    Rep ResourceCreationLimitPolicy x -> ResourceCreationLimitPolicy)
-> Generic ResourceCreationLimitPolicy
forall x.
Rep ResourceCreationLimitPolicy x -> ResourceCreationLimitPolicy
forall x.
ResourceCreationLimitPolicy -> Rep ResourceCreationLimitPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ResourceCreationLimitPolicy x -> ResourceCreationLimitPolicy
$cfrom :: forall x.
ResourceCreationLimitPolicy -> Rep ResourceCreationLimitPolicy x
Prelude.Generic)

-- |
-- Create a value of 'ResourceCreationLimitPolicy' 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:
--
-- 'newGameSessionsPerCreator'', 'resourceCreationLimitPolicy_newGameSessionsPerCreator' - The maximum number of game sessions that an individual can create during
-- the policy period.
--
-- 'policyPeriodInMinutes', 'resourceCreationLimitPolicy_policyPeriodInMinutes' - The time span used in evaluating the resource creation limit policy.
newResourceCreationLimitPolicy ::
  ResourceCreationLimitPolicy
newResourceCreationLimitPolicy :: ResourceCreationLimitPolicy
newResourceCreationLimitPolicy =
  ResourceCreationLimitPolicy' :: Maybe Natural -> Maybe Natural -> ResourceCreationLimitPolicy
ResourceCreationLimitPolicy'
    { $sel:newGameSessionsPerCreator':ResourceCreationLimitPolicy' :: Maybe Natural
newGameSessionsPerCreator' =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:policyPeriodInMinutes:ResourceCreationLimitPolicy' :: Maybe Natural
policyPeriodInMinutes = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of game sessions that an individual can create during
-- the policy period.
resourceCreationLimitPolicy_newGameSessionsPerCreator :: Lens.Lens' ResourceCreationLimitPolicy (Prelude.Maybe Prelude.Natural)
resourceCreationLimitPolicy_newGameSessionsPerCreator :: (Maybe Natural -> f (Maybe Natural))
-> ResourceCreationLimitPolicy -> f ResourceCreationLimitPolicy
resourceCreationLimitPolicy_newGameSessionsPerCreator = (ResourceCreationLimitPolicy -> Maybe Natural)
-> (ResourceCreationLimitPolicy
    -> Maybe Natural -> ResourceCreationLimitPolicy)
-> Lens
     ResourceCreationLimitPolicy
     ResourceCreationLimitPolicy
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceCreationLimitPolicy' {Maybe Natural
newGameSessionsPerCreator' :: Maybe Natural
$sel:newGameSessionsPerCreator':ResourceCreationLimitPolicy' :: ResourceCreationLimitPolicy -> Maybe Natural
newGameSessionsPerCreator'} -> Maybe Natural
newGameSessionsPerCreator') (\s :: ResourceCreationLimitPolicy
s@ResourceCreationLimitPolicy' {} Maybe Natural
a -> ResourceCreationLimitPolicy
s {$sel:newGameSessionsPerCreator':ResourceCreationLimitPolicy' :: Maybe Natural
newGameSessionsPerCreator' = Maybe Natural
a} :: ResourceCreationLimitPolicy)

-- | The time span used in evaluating the resource creation limit policy.
resourceCreationLimitPolicy_policyPeriodInMinutes :: Lens.Lens' ResourceCreationLimitPolicy (Prelude.Maybe Prelude.Natural)
resourceCreationLimitPolicy_policyPeriodInMinutes :: (Maybe Natural -> f (Maybe Natural))
-> ResourceCreationLimitPolicy -> f ResourceCreationLimitPolicy
resourceCreationLimitPolicy_policyPeriodInMinutes = (ResourceCreationLimitPolicy -> Maybe Natural)
-> (ResourceCreationLimitPolicy
    -> Maybe Natural -> ResourceCreationLimitPolicy)
-> Lens
     ResourceCreationLimitPolicy
     ResourceCreationLimitPolicy
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceCreationLimitPolicy' {Maybe Natural
policyPeriodInMinutes :: Maybe Natural
$sel:policyPeriodInMinutes:ResourceCreationLimitPolicy' :: ResourceCreationLimitPolicy -> Maybe Natural
policyPeriodInMinutes} -> Maybe Natural
policyPeriodInMinutes) (\s :: ResourceCreationLimitPolicy
s@ResourceCreationLimitPolicy' {} Maybe Natural
a -> ResourceCreationLimitPolicy
s {$sel:policyPeriodInMinutes:ResourceCreationLimitPolicy' :: Maybe Natural
policyPeriodInMinutes = Maybe Natural
a} :: ResourceCreationLimitPolicy)

instance Core.FromJSON ResourceCreationLimitPolicy where
  parseJSON :: Value -> Parser ResourceCreationLimitPolicy
parseJSON =
    String
-> (Object -> Parser ResourceCreationLimitPolicy)
-> Value
-> Parser ResourceCreationLimitPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResourceCreationLimitPolicy"
      ( \Object
x ->
          Maybe Natural -> Maybe Natural -> ResourceCreationLimitPolicy
ResourceCreationLimitPolicy'
            (Maybe Natural -> Maybe Natural -> ResourceCreationLimitPolicy)
-> Parser (Maybe Natural)
-> Parser (Maybe Natural -> ResourceCreationLimitPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"NewGameSessionsPerCreator")
            Parser (Maybe Natural -> ResourceCreationLimitPolicy)
-> Parser (Maybe Natural) -> Parser ResourceCreationLimitPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PolicyPeriodInMinutes")
      )

instance Prelude.Hashable ResourceCreationLimitPolicy

instance Prelude.NFData ResourceCreationLimitPolicy

instance Core.ToJSON ResourceCreationLimitPolicy where
  toJSON :: ResourceCreationLimitPolicy -> Value
toJSON ResourceCreationLimitPolicy' {Maybe Natural
policyPeriodInMinutes :: Maybe Natural
newGameSessionsPerCreator' :: Maybe Natural
$sel:policyPeriodInMinutes:ResourceCreationLimitPolicy' :: ResourceCreationLimitPolicy -> Maybe Natural
$sel:newGameSessionsPerCreator':ResourceCreationLimitPolicy' :: ResourceCreationLimitPolicy -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"NewGameSessionsPerCreator" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
newGameSessionsPerCreator',
            (Text
"PolicyPeriodInMinutes" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
policyPeriodInMinutes
          ]
      )