{-# 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.ComputeOptimizer.Types.SavingsOpportunity
-- 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.ComputeOptimizer.Types.SavingsOpportunity where

import Amazonka.ComputeOptimizer.Types.EstimatedMonthlySavings
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

-- | Describes the savings opportunity for recommendations of a given
-- resource type or for the recommendation option of an individual
-- resource.
--
-- Savings opportunity represents the estimated monthly savings you can
-- achieve by implementing a given Compute Optimizer recommendation.
--
-- Savings opportunity data requires that you opt in to Cost Explorer, as
-- well as activate __Receive Amazon EC2 resource recommendations__ in the
-- Cost Explorer preferences page. That creates a connection between Cost
-- Explorer and Compute Optimizer. With this connection, Cost Explorer
-- generates savings estimates considering the price of existing resources,
-- the price of recommended resources, and historical usage data. Estimated
-- monthly savings reflects the projected dollar savings associated with
-- each of the recommendations generated. For more information, see
-- <https://docs.aws.amazon.com/cost-management/latest/userguide/ce-enable.html Enabling Cost Explorer>
-- and
-- <https://docs.aws.amazon.com/cost-management/latest/userguide/ce-rightsizing.html Optimizing your cost with Rightsizing Recommendations>
-- in the /Cost Management User Guide/.
--
-- /See:/ 'newSavingsOpportunity' smart constructor.
data SavingsOpportunity = SavingsOpportunity'
  { -- | An object that describes the estimated monthly savings amount possible,
    -- based on On-Demand instance pricing, by adopting Compute Optimizer
    -- recommendations for a given resource.
    SavingsOpportunity -> Maybe EstimatedMonthlySavings
estimatedMonthlySavings :: Prelude.Maybe EstimatedMonthlySavings,
    -- | The estimated monthly savings possible as a percentage of monthly cost
    -- by adopting Compute Optimizer recommendations for a given resource.
    SavingsOpportunity -> Maybe Double
savingsOpportunityPercentage :: Prelude.Maybe Prelude.Double
  }
  deriving (SavingsOpportunity -> SavingsOpportunity -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SavingsOpportunity -> SavingsOpportunity -> Bool
$c/= :: SavingsOpportunity -> SavingsOpportunity -> Bool
== :: SavingsOpportunity -> SavingsOpportunity -> Bool
$c== :: SavingsOpportunity -> SavingsOpportunity -> Bool
Prelude.Eq, ReadPrec [SavingsOpportunity]
ReadPrec SavingsOpportunity
Int -> ReadS SavingsOpportunity
ReadS [SavingsOpportunity]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SavingsOpportunity]
$creadListPrec :: ReadPrec [SavingsOpportunity]
readPrec :: ReadPrec SavingsOpportunity
$creadPrec :: ReadPrec SavingsOpportunity
readList :: ReadS [SavingsOpportunity]
$creadList :: ReadS [SavingsOpportunity]
readsPrec :: Int -> ReadS SavingsOpportunity
$creadsPrec :: Int -> ReadS SavingsOpportunity
Prelude.Read, Int -> SavingsOpportunity -> ShowS
[SavingsOpportunity] -> ShowS
SavingsOpportunity -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SavingsOpportunity] -> ShowS
$cshowList :: [SavingsOpportunity] -> ShowS
show :: SavingsOpportunity -> String
$cshow :: SavingsOpportunity -> String
showsPrec :: Int -> SavingsOpportunity -> ShowS
$cshowsPrec :: Int -> SavingsOpportunity -> ShowS
Prelude.Show, forall x. Rep SavingsOpportunity x -> SavingsOpportunity
forall x. SavingsOpportunity -> Rep SavingsOpportunity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SavingsOpportunity x -> SavingsOpportunity
$cfrom :: forall x. SavingsOpportunity -> Rep SavingsOpportunity x
Prelude.Generic)

-- |
-- Create a value of 'SavingsOpportunity' 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:
--
-- 'estimatedMonthlySavings', 'savingsOpportunity_estimatedMonthlySavings' - An object that describes the estimated monthly savings amount possible,
-- based on On-Demand instance pricing, by adopting Compute Optimizer
-- recommendations for a given resource.
--
-- 'savingsOpportunityPercentage', 'savingsOpportunity_savingsOpportunityPercentage' - The estimated monthly savings possible as a percentage of monthly cost
-- by adopting Compute Optimizer recommendations for a given resource.
newSavingsOpportunity ::
  SavingsOpportunity
newSavingsOpportunity :: SavingsOpportunity
newSavingsOpportunity =
  SavingsOpportunity'
    { $sel:estimatedMonthlySavings:SavingsOpportunity' :: Maybe EstimatedMonthlySavings
estimatedMonthlySavings =
        forall a. Maybe a
Prelude.Nothing,
      $sel:savingsOpportunityPercentage:SavingsOpportunity' :: Maybe Double
savingsOpportunityPercentage = forall a. Maybe a
Prelude.Nothing
    }

-- | An object that describes the estimated monthly savings amount possible,
-- based on On-Demand instance pricing, by adopting Compute Optimizer
-- recommendations for a given resource.
savingsOpportunity_estimatedMonthlySavings :: Lens.Lens' SavingsOpportunity (Prelude.Maybe EstimatedMonthlySavings)
savingsOpportunity_estimatedMonthlySavings :: Lens' SavingsOpportunity (Maybe EstimatedMonthlySavings)
savingsOpportunity_estimatedMonthlySavings = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SavingsOpportunity' {Maybe EstimatedMonthlySavings
estimatedMonthlySavings :: Maybe EstimatedMonthlySavings
$sel:estimatedMonthlySavings:SavingsOpportunity' :: SavingsOpportunity -> Maybe EstimatedMonthlySavings
estimatedMonthlySavings} -> Maybe EstimatedMonthlySavings
estimatedMonthlySavings) (\s :: SavingsOpportunity
s@SavingsOpportunity' {} Maybe EstimatedMonthlySavings
a -> SavingsOpportunity
s {$sel:estimatedMonthlySavings:SavingsOpportunity' :: Maybe EstimatedMonthlySavings
estimatedMonthlySavings = Maybe EstimatedMonthlySavings
a} :: SavingsOpportunity)

-- | The estimated monthly savings possible as a percentage of monthly cost
-- by adopting Compute Optimizer recommendations for a given resource.
savingsOpportunity_savingsOpportunityPercentage :: Lens.Lens' SavingsOpportunity (Prelude.Maybe Prelude.Double)
savingsOpportunity_savingsOpportunityPercentage :: Lens' SavingsOpportunity (Maybe Double)
savingsOpportunity_savingsOpportunityPercentage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SavingsOpportunity' {Maybe Double
savingsOpportunityPercentage :: Maybe Double
$sel:savingsOpportunityPercentage:SavingsOpportunity' :: SavingsOpportunity -> Maybe Double
savingsOpportunityPercentage} -> Maybe Double
savingsOpportunityPercentage) (\s :: SavingsOpportunity
s@SavingsOpportunity' {} Maybe Double
a -> SavingsOpportunity
s {$sel:savingsOpportunityPercentage:SavingsOpportunity' :: Maybe Double
savingsOpportunityPercentage = Maybe Double
a} :: SavingsOpportunity)

instance Data.FromJSON SavingsOpportunity where
  parseJSON :: Value -> Parser SavingsOpportunity
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SavingsOpportunity"
      ( \Object
x ->
          Maybe EstimatedMonthlySavings -> Maybe Double -> SavingsOpportunity
SavingsOpportunity'
            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
"estimatedMonthlySavings")
            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
"savingsOpportunityPercentage")
      )

instance Prelude.Hashable SavingsOpportunity where
  hashWithSalt :: Int -> SavingsOpportunity -> Int
hashWithSalt Int
_salt SavingsOpportunity' {Maybe Double
Maybe EstimatedMonthlySavings
savingsOpportunityPercentage :: Maybe Double
estimatedMonthlySavings :: Maybe EstimatedMonthlySavings
$sel:savingsOpportunityPercentage:SavingsOpportunity' :: SavingsOpportunity -> Maybe Double
$sel:estimatedMonthlySavings:SavingsOpportunity' :: SavingsOpportunity -> Maybe EstimatedMonthlySavings
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EstimatedMonthlySavings
estimatedMonthlySavings
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
savingsOpportunityPercentage

instance Prelude.NFData SavingsOpportunity where
  rnf :: SavingsOpportunity -> ()
rnf SavingsOpportunity' {Maybe Double
Maybe EstimatedMonthlySavings
savingsOpportunityPercentage :: Maybe Double
estimatedMonthlySavings :: Maybe EstimatedMonthlySavings
$sel:savingsOpportunityPercentage:SavingsOpportunity' :: SavingsOpportunity -> Maybe Double
$sel:estimatedMonthlySavings:SavingsOpportunity' :: SavingsOpportunity -> Maybe EstimatedMonthlySavings
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe EstimatedMonthlySavings
estimatedMonthlySavings
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
savingsOpportunityPercentage