{-# 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.Athena.Types.ResultReuseByAgeConfiguration
-- 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.Athena.Types.ResultReuseByAgeConfiguration 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 whether previous query results are reused, and if so, their
-- maximum age.
--
-- /See:/ 'newResultReuseByAgeConfiguration' smart constructor.
data ResultReuseByAgeConfiguration = ResultReuseByAgeConfiguration'
  { -- | Specifies, in minutes, the maximum age of a previous query result that
    -- Athena should consider for reuse. The default is 60.
    ResultReuseByAgeConfiguration -> Maybe Natural
maxAgeInMinutes :: Prelude.Maybe Prelude.Natural,
    -- | True if previous query results can be reused when the query is run;
    -- otherwise, false. The default is false.
    ResultReuseByAgeConfiguration -> Bool
enabled :: Prelude.Bool
  }
  deriving (ResultReuseByAgeConfiguration
-> ResultReuseByAgeConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultReuseByAgeConfiguration
-> ResultReuseByAgeConfiguration -> Bool
$c/= :: ResultReuseByAgeConfiguration
-> ResultReuseByAgeConfiguration -> Bool
== :: ResultReuseByAgeConfiguration
-> ResultReuseByAgeConfiguration -> Bool
$c== :: ResultReuseByAgeConfiguration
-> ResultReuseByAgeConfiguration -> Bool
Prelude.Eq, ReadPrec [ResultReuseByAgeConfiguration]
ReadPrec ResultReuseByAgeConfiguration
Int -> ReadS ResultReuseByAgeConfiguration
ReadS [ResultReuseByAgeConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResultReuseByAgeConfiguration]
$creadListPrec :: ReadPrec [ResultReuseByAgeConfiguration]
readPrec :: ReadPrec ResultReuseByAgeConfiguration
$creadPrec :: ReadPrec ResultReuseByAgeConfiguration
readList :: ReadS [ResultReuseByAgeConfiguration]
$creadList :: ReadS [ResultReuseByAgeConfiguration]
readsPrec :: Int -> ReadS ResultReuseByAgeConfiguration
$creadsPrec :: Int -> ReadS ResultReuseByAgeConfiguration
Prelude.Read, Int -> ResultReuseByAgeConfiguration -> ShowS
[ResultReuseByAgeConfiguration] -> ShowS
ResultReuseByAgeConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultReuseByAgeConfiguration] -> ShowS
$cshowList :: [ResultReuseByAgeConfiguration] -> ShowS
show :: ResultReuseByAgeConfiguration -> String
$cshow :: ResultReuseByAgeConfiguration -> String
showsPrec :: Int -> ResultReuseByAgeConfiguration -> ShowS
$cshowsPrec :: Int -> ResultReuseByAgeConfiguration -> ShowS
Prelude.Show, forall x.
Rep ResultReuseByAgeConfiguration x
-> ResultReuseByAgeConfiguration
forall x.
ResultReuseByAgeConfiguration
-> Rep ResultReuseByAgeConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ResultReuseByAgeConfiguration x
-> ResultReuseByAgeConfiguration
$cfrom :: forall x.
ResultReuseByAgeConfiguration
-> Rep ResultReuseByAgeConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ResultReuseByAgeConfiguration' 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:
--
-- 'maxAgeInMinutes', 'resultReuseByAgeConfiguration_maxAgeInMinutes' - Specifies, in minutes, the maximum age of a previous query result that
-- Athena should consider for reuse. The default is 60.
--
-- 'enabled', 'resultReuseByAgeConfiguration_enabled' - True if previous query results can be reused when the query is run;
-- otherwise, false. The default is false.
newResultReuseByAgeConfiguration ::
  -- | 'enabled'
  Prelude.Bool ->
  ResultReuseByAgeConfiguration
newResultReuseByAgeConfiguration :: Bool -> ResultReuseByAgeConfiguration
newResultReuseByAgeConfiguration Bool
pEnabled_ =
  ResultReuseByAgeConfiguration'
    { $sel:maxAgeInMinutes:ResultReuseByAgeConfiguration' :: Maybe Natural
maxAgeInMinutes =
        forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:ResultReuseByAgeConfiguration' :: Bool
enabled = Bool
pEnabled_
    }

-- | Specifies, in minutes, the maximum age of a previous query result that
-- Athena should consider for reuse. The default is 60.
resultReuseByAgeConfiguration_maxAgeInMinutes :: Lens.Lens' ResultReuseByAgeConfiguration (Prelude.Maybe Prelude.Natural)
resultReuseByAgeConfiguration_maxAgeInMinutes :: Lens' ResultReuseByAgeConfiguration (Maybe Natural)
resultReuseByAgeConfiguration_maxAgeInMinutes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultReuseByAgeConfiguration' {Maybe Natural
maxAgeInMinutes :: Maybe Natural
$sel:maxAgeInMinutes:ResultReuseByAgeConfiguration' :: ResultReuseByAgeConfiguration -> Maybe Natural
maxAgeInMinutes} -> Maybe Natural
maxAgeInMinutes) (\s :: ResultReuseByAgeConfiguration
s@ResultReuseByAgeConfiguration' {} Maybe Natural
a -> ResultReuseByAgeConfiguration
s {$sel:maxAgeInMinutes:ResultReuseByAgeConfiguration' :: Maybe Natural
maxAgeInMinutes = Maybe Natural
a} :: ResultReuseByAgeConfiguration)

-- | True if previous query results can be reused when the query is run;
-- otherwise, false. The default is false.
resultReuseByAgeConfiguration_enabled :: Lens.Lens' ResultReuseByAgeConfiguration Prelude.Bool
resultReuseByAgeConfiguration_enabled :: Lens' ResultReuseByAgeConfiguration Bool
resultReuseByAgeConfiguration_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultReuseByAgeConfiguration' {Bool
enabled :: Bool
$sel:enabled:ResultReuseByAgeConfiguration' :: ResultReuseByAgeConfiguration -> Bool
enabled} -> Bool
enabled) (\s :: ResultReuseByAgeConfiguration
s@ResultReuseByAgeConfiguration' {} Bool
a -> ResultReuseByAgeConfiguration
s {$sel:enabled:ResultReuseByAgeConfiguration' :: Bool
enabled = Bool
a} :: ResultReuseByAgeConfiguration)

instance Data.FromJSON ResultReuseByAgeConfiguration where
  parseJSON :: Value -> Parser ResultReuseByAgeConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ResultReuseByAgeConfiguration"
      ( \Object
x ->
          Maybe Natural -> Bool -> ResultReuseByAgeConfiguration
ResultReuseByAgeConfiguration'
            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
"MaxAgeInMinutes")
            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
"Enabled")
      )

instance
  Prelude.Hashable
    ResultReuseByAgeConfiguration
  where
  hashWithSalt :: Int -> ResultReuseByAgeConfiguration -> Int
hashWithSalt Int
_salt ResultReuseByAgeConfiguration' {Bool
Maybe Natural
enabled :: Bool
maxAgeInMinutes :: Maybe Natural
$sel:enabled:ResultReuseByAgeConfiguration' :: ResultReuseByAgeConfiguration -> Bool
$sel:maxAgeInMinutes:ResultReuseByAgeConfiguration' :: ResultReuseByAgeConfiguration -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxAgeInMinutes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
enabled

instance Prelude.NFData ResultReuseByAgeConfiguration where
  rnf :: ResultReuseByAgeConfiguration -> ()
rnf ResultReuseByAgeConfiguration' {Bool
Maybe Natural
enabled :: Bool
maxAgeInMinutes :: Maybe Natural
$sel:enabled:ResultReuseByAgeConfiguration' :: ResultReuseByAgeConfiguration -> Bool
$sel:maxAgeInMinutes:ResultReuseByAgeConfiguration' :: ResultReuseByAgeConfiguration -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxAgeInMinutes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
enabled

instance Data.ToJSON ResultReuseByAgeConfiguration where
  toJSON :: ResultReuseByAgeConfiguration -> Value
toJSON ResultReuseByAgeConfiguration' {Bool
Maybe Natural
enabled :: Bool
maxAgeInMinutes :: Maybe Natural
$sel:enabled:ResultReuseByAgeConfiguration' :: ResultReuseByAgeConfiguration -> Bool
$sel:maxAgeInMinutes:ResultReuseByAgeConfiguration' :: ResultReuseByAgeConfiguration -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaxAgeInMinutes" 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 Natural
maxAgeInMinutes,
            forall a. a -> Maybe a
Prelude.Just (Key
"Enabled" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Bool
enabled)
          ]
      )