{-# 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.EC2.Types.CapacityReservationOptions
-- 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.EC2.Types.CapacityReservationOptions where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EC2.Internal
import Amazonka.EC2.Types.FleetCapacityReservationUsageStrategy
import qualified Amazonka.Prelude as Prelude

-- | Describes the strategy for using unused Capacity Reservations for
-- fulfilling On-Demand capacity.
--
-- This strategy can only be used if the EC2 Fleet is of type @instant@.
--
-- For more information about Capacity Reservations, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-capacity-reservations.html On-Demand Capacity Reservations>
-- in the /Amazon EC2 User Guide/. For examples of using Capacity
-- Reservations in an EC2 Fleet, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-examples.html EC2 Fleet example configurations>
-- in the /Amazon EC2 User Guide/.
--
-- /See:/ 'newCapacityReservationOptions' smart constructor.
data CapacityReservationOptions = CapacityReservationOptions'
  { -- | Indicates whether to use unused Capacity Reservations for fulfilling
    -- On-Demand capacity.
    --
    -- If you specify @use-capacity-reservations-first@, the fleet uses unused
    -- Capacity Reservations to fulfill On-Demand capacity up to the target
    -- On-Demand capacity. If multiple instance pools have unused Capacity
    -- Reservations, the On-Demand allocation strategy (@lowest-price@ or
    -- @prioritized@) is applied. If the number of unused Capacity Reservations
    -- is less than the On-Demand target capacity, the remaining On-Demand
    -- target capacity is launched according to the On-Demand allocation
    -- strategy (@lowest-price@ or @prioritized@).
    --
    -- If you do not specify a value, the fleet fulfils the On-Demand capacity
    -- according to the chosen On-Demand allocation strategy.
    CapacityReservationOptions
-> Maybe FleetCapacityReservationUsageStrategy
usageStrategy :: Prelude.Maybe FleetCapacityReservationUsageStrategy
  }
  deriving (CapacityReservationOptions -> CapacityReservationOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CapacityReservationOptions -> CapacityReservationOptions -> Bool
$c/= :: CapacityReservationOptions -> CapacityReservationOptions -> Bool
== :: CapacityReservationOptions -> CapacityReservationOptions -> Bool
$c== :: CapacityReservationOptions -> CapacityReservationOptions -> Bool
Prelude.Eq, ReadPrec [CapacityReservationOptions]
ReadPrec CapacityReservationOptions
Int -> ReadS CapacityReservationOptions
ReadS [CapacityReservationOptions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CapacityReservationOptions]
$creadListPrec :: ReadPrec [CapacityReservationOptions]
readPrec :: ReadPrec CapacityReservationOptions
$creadPrec :: ReadPrec CapacityReservationOptions
readList :: ReadS [CapacityReservationOptions]
$creadList :: ReadS [CapacityReservationOptions]
readsPrec :: Int -> ReadS CapacityReservationOptions
$creadsPrec :: Int -> ReadS CapacityReservationOptions
Prelude.Read, Int -> CapacityReservationOptions -> ShowS
[CapacityReservationOptions] -> ShowS
CapacityReservationOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CapacityReservationOptions] -> ShowS
$cshowList :: [CapacityReservationOptions] -> ShowS
show :: CapacityReservationOptions -> String
$cshow :: CapacityReservationOptions -> String
showsPrec :: Int -> CapacityReservationOptions -> ShowS
$cshowsPrec :: Int -> CapacityReservationOptions -> ShowS
Prelude.Show, forall x.
Rep CapacityReservationOptions x -> CapacityReservationOptions
forall x.
CapacityReservationOptions -> Rep CapacityReservationOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CapacityReservationOptions x -> CapacityReservationOptions
$cfrom :: forall x.
CapacityReservationOptions -> Rep CapacityReservationOptions x
Prelude.Generic)

-- |
-- Create a value of 'CapacityReservationOptions' 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:
--
-- 'usageStrategy', 'capacityReservationOptions_usageStrategy' - Indicates whether to use unused Capacity Reservations for fulfilling
-- On-Demand capacity.
--
-- If you specify @use-capacity-reservations-first@, the fleet uses unused
-- Capacity Reservations to fulfill On-Demand capacity up to the target
-- On-Demand capacity. If multiple instance pools have unused Capacity
-- Reservations, the On-Demand allocation strategy (@lowest-price@ or
-- @prioritized@) is applied. If the number of unused Capacity Reservations
-- is less than the On-Demand target capacity, the remaining On-Demand
-- target capacity is launched according to the On-Demand allocation
-- strategy (@lowest-price@ or @prioritized@).
--
-- If you do not specify a value, the fleet fulfils the On-Demand capacity
-- according to the chosen On-Demand allocation strategy.
newCapacityReservationOptions ::
  CapacityReservationOptions
newCapacityReservationOptions :: CapacityReservationOptions
newCapacityReservationOptions =
  CapacityReservationOptions'
    { $sel:usageStrategy:CapacityReservationOptions' :: Maybe FleetCapacityReservationUsageStrategy
usageStrategy =
        forall a. Maybe a
Prelude.Nothing
    }

-- | Indicates whether to use unused Capacity Reservations for fulfilling
-- On-Demand capacity.
--
-- If you specify @use-capacity-reservations-first@, the fleet uses unused
-- Capacity Reservations to fulfill On-Demand capacity up to the target
-- On-Demand capacity. If multiple instance pools have unused Capacity
-- Reservations, the On-Demand allocation strategy (@lowest-price@ or
-- @prioritized@) is applied. If the number of unused Capacity Reservations
-- is less than the On-Demand target capacity, the remaining On-Demand
-- target capacity is launched according to the On-Demand allocation
-- strategy (@lowest-price@ or @prioritized@).
--
-- If you do not specify a value, the fleet fulfils the On-Demand capacity
-- according to the chosen On-Demand allocation strategy.
capacityReservationOptions_usageStrategy :: Lens.Lens' CapacityReservationOptions (Prelude.Maybe FleetCapacityReservationUsageStrategy)
capacityReservationOptions_usageStrategy :: Lens'
  CapacityReservationOptions
  (Maybe FleetCapacityReservationUsageStrategy)
capacityReservationOptions_usageStrategy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CapacityReservationOptions' {Maybe FleetCapacityReservationUsageStrategy
usageStrategy :: Maybe FleetCapacityReservationUsageStrategy
$sel:usageStrategy:CapacityReservationOptions' :: CapacityReservationOptions
-> Maybe FleetCapacityReservationUsageStrategy
usageStrategy} -> Maybe FleetCapacityReservationUsageStrategy
usageStrategy) (\s :: CapacityReservationOptions
s@CapacityReservationOptions' {} Maybe FleetCapacityReservationUsageStrategy
a -> CapacityReservationOptions
s {$sel:usageStrategy:CapacityReservationOptions' :: Maybe FleetCapacityReservationUsageStrategy
usageStrategy = Maybe FleetCapacityReservationUsageStrategy
a} :: CapacityReservationOptions)

instance Data.FromXML CapacityReservationOptions where
  parseXML :: [Node] -> Either String CapacityReservationOptions
parseXML [Node]
x =
    Maybe FleetCapacityReservationUsageStrategy
-> CapacityReservationOptions
CapacityReservationOptions'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"usageStrategy")

instance Prelude.Hashable CapacityReservationOptions where
  hashWithSalt :: Int -> CapacityReservationOptions -> Int
hashWithSalt Int
_salt CapacityReservationOptions' {Maybe FleetCapacityReservationUsageStrategy
usageStrategy :: Maybe FleetCapacityReservationUsageStrategy
$sel:usageStrategy:CapacityReservationOptions' :: CapacityReservationOptions
-> Maybe FleetCapacityReservationUsageStrategy
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe FleetCapacityReservationUsageStrategy
usageStrategy

instance Prelude.NFData CapacityReservationOptions where
  rnf :: CapacityReservationOptions -> ()
rnf CapacityReservationOptions' {Maybe FleetCapacityReservationUsageStrategy
usageStrategy :: Maybe FleetCapacityReservationUsageStrategy
$sel:usageStrategy:CapacityReservationOptions' :: CapacityReservationOptions
-> Maybe FleetCapacityReservationUsageStrategy
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe FleetCapacityReservationUsageStrategy
usageStrategy