{-# 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.CodeGuruProfiler.Types.Recommendation
-- 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.CodeGuruProfiler.Types.Recommendation where

import Amazonka.CodeGuruProfiler.Types.Match
import Amazonka.CodeGuruProfiler.Types.Pattern
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A potential improvement that was found from analyzing the profiling
-- data.
--
-- /See:/ 'newRecommendation' smart constructor.
data Recommendation = Recommendation'
  { -- | How many different places in the profile graph triggered a match.
    Recommendation -> Int
allMatchesCount :: Prelude.Int,
    -- | How much of the total sample count is potentially affected.
    Recommendation -> Double
allMatchesSum :: Prelude.Double,
    -- | End time of the profile that was used by this analysis. This is
    -- specified using the ISO 8601 format. For example,
    -- 2020-06-01T13:15:02.001Z represents 1 millisecond past June 1, 2020
    -- 1:15:02 PM UTC.
    Recommendation -> POSIX
endTime :: Core.POSIX,
    -- | The pattern that analysis recognized in the profile to make this
    -- recommendation.
    Recommendation -> Pattern
pattern' :: Pattern,
    -- | The start time of the profile that was used by this analysis. This is
    -- specified using the ISO 8601 format. For example,
    -- 2020-06-01T13:15:02.001Z represents 1 millisecond past June 1, 2020
    -- 1:15:02 PM UTC.
    Recommendation -> POSIX
startTime :: Core.POSIX,
    -- | List of the matches with most impact.
    Recommendation -> [Match]
topMatches :: [Match]
  }
  deriving (Recommendation -> Recommendation -> Bool
(Recommendation -> Recommendation -> Bool)
-> (Recommendation -> Recommendation -> Bool) -> Eq Recommendation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Recommendation -> Recommendation -> Bool
$c/= :: Recommendation -> Recommendation -> Bool
== :: Recommendation -> Recommendation -> Bool
$c== :: Recommendation -> Recommendation -> Bool
Prelude.Eq, ReadPrec [Recommendation]
ReadPrec Recommendation
Int -> ReadS Recommendation
ReadS [Recommendation]
(Int -> ReadS Recommendation)
-> ReadS [Recommendation]
-> ReadPrec Recommendation
-> ReadPrec [Recommendation]
-> Read Recommendation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Recommendation]
$creadListPrec :: ReadPrec [Recommendation]
readPrec :: ReadPrec Recommendation
$creadPrec :: ReadPrec Recommendation
readList :: ReadS [Recommendation]
$creadList :: ReadS [Recommendation]
readsPrec :: Int -> ReadS Recommendation
$creadsPrec :: Int -> ReadS Recommendation
Prelude.Read, Int -> Recommendation -> ShowS
[Recommendation] -> ShowS
Recommendation -> String
(Int -> Recommendation -> ShowS)
-> (Recommendation -> String)
-> ([Recommendation] -> ShowS)
-> Show Recommendation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Recommendation] -> ShowS
$cshowList :: [Recommendation] -> ShowS
show :: Recommendation -> String
$cshow :: Recommendation -> String
showsPrec :: Int -> Recommendation -> ShowS
$cshowsPrec :: Int -> Recommendation -> ShowS
Prelude.Show, (forall x. Recommendation -> Rep Recommendation x)
-> (forall x. Rep Recommendation x -> Recommendation)
-> Generic Recommendation
forall x. Rep Recommendation x -> Recommendation
forall x. Recommendation -> Rep Recommendation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Recommendation x -> Recommendation
$cfrom :: forall x. Recommendation -> Rep Recommendation x
Prelude.Generic)

-- |
-- Create a value of 'Recommendation' 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:
--
-- 'allMatchesCount', 'recommendation_allMatchesCount' - How many different places in the profile graph triggered a match.
--
-- 'allMatchesSum', 'recommendation_allMatchesSum' - How much of the total sample count is potentially affected.
--
-- 'endTime', 'recommendation_endTime' - End time of the profile that was used by this analysis. This is
-- specified using the ISO 8601 format. For example,
-- 2020-06-01T13:15:02.001Z represents 1 millisecond past June 1, 2020
-- 1:15:02 PM UTC.
--
-- 'pattern'', 'recommendation_pattern' - The pattern that analysis recognized in the profile to make this
-- recommendation.
--
-- 'startTime', 'recommendation_startTime' - The start time of the profile that was used by this analysis. This is
-- specified using the ISO 8601 format. For example,
-- 2020-06-01T13:15:02.001Z represents 1 millisecond past June 1, 2020
-- 1:15:02 PM UTC.
--
-- 'topMatches', 'recommendation_topMatches' - List of the matches with most impact.
newRecommendation ::
  -- | 'allMatchesCount'
  Prelude.Int ->
  -- | 'allMatchesSum'
  Prelude.Double ->
  -- | 'endTime'
  Prelude.UTCTime ->
  -- | 'pattern''
  Pattern ->
  -- | 'startTime'
  Prelude.UTCTime ->
  Recommendation
newRecommendation :: Int -> Double -> UTCTime -> Pattern -> UTCTime -> Recommendation
newRecommendation
  Int
pAllMatchesCount_
  Double
pAllMatchesSum_
  UTCTime
pEndTime_
  Pattern
pPattern_
  UTCTime
pStartTime_ =
    Recommendation' :: Int
-> Double -> POSIX -> Pattern -> POSIX -> [Match] -> Recommendation
Recommendation'
      { $sel:allMatchesCount:Recommendation' :: Int
allMatchesCount =
          Int
pAllMatchesCount_,
        $sel:allMatchesSum:Recommendation' :: Double
allMatchesSum = Double
pAllMatchesSum_,
        $sel:endTime:Recommendation' :: POSIX
endTime = Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pEndTime_,
        $sel:pattern':Recommendation' :: Pattern
pattern' = Pattern
pPattern_,
        $sel:startTime:Recommendation' :: POSIX
startTime = Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pStartTime_,
        $sel:topMatches:Recommendation' :: [Match]
topMatches = [Match]
forall a. Monoid a => a
Prelude.mempty
      }

-- | How many different places in the profile graph triggered a match.
recommendation_allMatchesCount :: Lens.Lens' Recommendation Prelude.Int
recommendation_allMatchesCount :: (Int -> f Int) -> Recommendation -> f Recommendation
recommendation_allMatchesCount = (Recommendation -> Int)
-> (Recommendation -> Int -> Recommendation)
-> Lens Recommendation Recommendation Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Recommendation' {Int
allMatchesCount :: Int
$sel:allMatchesCount:Recommendation' :: Recommendation -> Int
allMatchesCount} -> Int
allMatchesCount) (\s :: Recommendation
s@Recommendation' {} Int
a -> Recommendation
s {$sel:allMatchesCount:Recommendation' :: Int
allMatchesCount = Int
a} :: Recommendation)

-- | How much of the total sample count is potentially affected.
recommendation_allMatchesSum :: Lens.Lens' Recommendation Prelude.Double
recommendation_allMatchesSum :: (Double -> f Double) -> Recommendation -> f Recommendation
recommendation_allMatchesSum = (Recommendation -> Double)
-> (Recommendation -> Double -> Recommendation)
-> Lens Recommendation Recommendation Double Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Recommendation' {Double
allMatchesSum :: Double
$sel:allMatchesSum:Recommendation' :: Recommendation -> Double
allMatchesSum} -> Double
allMatchesSum) (\s :: Recommendation
s@Recommendation' {} Double
a -> Recommendation
s {$sel:allMatchesSum:Recommendation' :: Double
allMatchesSum = Double
a} :: Recommendation)

-- | End time of the profile that was used by this analysis. This is
-- specified using the ISO 8601 format. For example,
-- 2020-06-01T13:15:02.001Z represents 1 millisecond past June 1, 2020
-- 1:15:02 PM UTC.
recommendation_endTime :: Lens.Lens' Recommendation Prelude.UTCTime
recommendation_endTime :: (UTCTime -> f UTCTime) -> Recommendation -> f Recommendation
recommendation_endTime = (Recommendation -> POSIX)
-> (Recommendation -> POSIX -> Recommendation)
-> Lens Recommendation Recommendation POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Recommendation' {POSIX
endTime :: POSIX
$sel:endTime:Recommendation' :: Recommendation -> POSIX
endTime} -> POSIX
endTime) (\s :: Recommendation
s@Recommendation' {} POSIX
a -> Recommendation
s {$sel:endTime:Recommendation' :: POSIX
endTime = POSIX
a} :: Recommendation) ((POSIX -> f POSIX) -> Recommendation -> f Recommendation)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> Recommendation
-> f Recommendation
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The pattern that analysis recognized in the profile to make this
-- recommendation.
recommendation_pattern :: Lens.Lens' Recommendation Pattern
recommendation_pattern :: (Pattern -> f Pattern) -> Recommendation -> f Recommendation
recommendation_pattern = (Recommendation -> Pattern)
-> (Recommendation -> Pattern -> Recommendation)
-> Lens Recommendation Recommendation Pattern Pattern
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Recommendation' {Pattern
pattern' :: Pattern
$sel:pattern':Recommendation' :: Recommendation -> Pattern
pattern'} -> Pattern
pattern') (\s :: Recommendation
s@Recommendation' {} Pattern
a -> Recommendation
s {$sel:pattern':Recommendation' :: Pattern
pattern' = Pattern
a} :: Recommendation)

-- | The start time of the profile that was used by this analysis. This is
-- specified using the ISO 8601 format. For example,
-- 2020-06-01T13:15:02.001Z represents 1 millisecond past June 1, 2020
-- 1:15:02 PM UTC.
recommendation_startTime :: Lens.Lens' Recommendation Prelude.UTCTime
recommendation_startTime :: (UTCTime -> f UTCTime) -> Recommendation -> f Recommendation
recommendation_startTime = (Recommendation -> POSIX)
-> (Recommendation -> POSIX -> Recommendation)
-> Lens Recommendation Recommendation POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Recommendation' {POSIX
startTime :: POSIX
$sel:startTime:Recommendation' :: Recommendation -> POSIX
startTime} -> POSIX
startTime) (\s :: Recommendation
s@Recommendation' {} POSIX
a -> Recommendation
s {$sel:startTime:Recommendation' :: POSIX
startTime = POSIX
a} :: Recommendation) ((POSIX -> f POSIX) -> Recommendation -> f Recommendation)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> Recommendation
-> f Recommendation
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | List of the matches with most impact.
recommendation_topMatches :: Lens.Lens' Recommendation [Match]
recommendation_topMatches :: ([Match] -> f [Match]) -> Recommendation -> f Recommendation
recommendation_topMatches = (Recommendation -> [Match])
-> (Recommendation -> [Match] -> Recommendation)
-> Lens Recommendation Recommendation [Match] [Match]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Recommendation' {[Match]
topMatches :: [Match]
$sel:topMatches:Recommendation' :: Recommendation -> [Match]
topMatches} -> [Match]
topMatches) (\s :: Recommendation
s@Recommendation' {} [Match]
a -> Recommendation
s {$sel:topMatches:Recommendation' :: [Match]
topMatches = [Match]
a} :: Recommendation) (([Match] -> f [Match]) -> Recommendation -> f Recommendation)
-> (([Match] -> f [Match]) -> [Match] -> f [Match])
-> ([Match] -> f [Match])
-> Recommendation
-> f Recommendation
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Match] -> f [Match]) -> [Match] -> f [Match]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Recommendation where
  parseJSON :: Value -> Parser Recommendation
parseJSON =
    String
-> (Object -> Parser Recommendation)
-> Value
-> Parser Recommendation
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Recommendation"
      ( \Object
x ->
          Int
-> Double -> POSIX -> Pattern -> POSIX -> [Match] -> Recommendation
Recommendation'
            (Int
 -> Double
 -> POSIX
 -> Pattern
 -> POSIX
 -> [Match]
 -> Recommendation)
-> Parser Int
-> Parser
     (Double -> POSIX -> Pattern -> POSIX -> [Match] -> Recommendation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"allMatchesCount")
            Parser
  (Double -> POSIX -> Pattern -> POSIX -> [Match] -> Recommendation)
-> Parser Double
-> Parser (POSIX -> Pattern -> POSIX -> [Match] -> Recommendation)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Double
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"allMatchesSum")
            Parser (POSIX -> Pattern -> POSIX -> [Match] -> Recommendation)
-> Parser POSIX
-> Parser (Pattern -> POSIX -> [Match] -> Recommendation)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"endTime")
            Parser (Pattern -> POSIX -> [Match] -> Recommendation)
-> Parser Pattern -> Parser (POSIX -> [Match] -> Recommendation)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Pattern
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"pattern")
            Parser (POSIX -> [Match] -> Recommendation)
-> Parser POSIX -> Parser ([Match] -> Recommendation)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"startTime")
            Parser ([Match] -> Recommendation)
-> Parser [Match] -> Parser Recommendation
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [Match])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"topMatches" Parser (Maybe [Match]) -> [Match] -> Parser [Match]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Match]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Recommendation

instance Prelude.NFData Recommendation