{-# 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.AppSync.Types.CachingConfig
-- 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.AppSync.Types.CachingConfig where

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

-- | The caching configuration for a resolver that has caching enabled.
--
-- /See:/ 'newCachingConfig' smart constructor.
data CachingConfig = CachingConfig'
  { -- | The TTL in seconds for a resolver that has caching enabled.
    --
    -- Valid values are between 1 and 3600 seconds.
    CachingConfig -> Maybe Integer
ttl :: Prelude.Maybe Prelude.Integer,
    -- | The caching keys for a resolver that has caching enabled.
    --
    -- Valid values are entries from the @$context.arguments@,
    -- @$context.source@, and @$context.identity@ maps.
    CachingConfig -> Maybe [Text]
cachingKeys :: Prelude.Maybe [Prelude.Text]
  }
  deriving (CachingConfig -> CachingConfig -> Bool
(CachingConfig -> CachingConfig -> Bool)
-> (CachingConfig -> CachingConfig -> Bool) -> Eq CachingConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CachingConfig -> CachingConfig -> Bool
$c/= :: CachingConfig -> CachingConfig -> Bool
== :: CachingConfig -> CachingConfig -> Bool
$c== :: CachingConfig -> CachingConfig -> Bool
Prelude.Eq, ReadPrec [CachingConfig]
ReadPrec CachingConfig
Int -> ReadS CachingConfig
ReadS [CachingConfig]
(Int -> ReadS CachingConfig)
-> ReadS [CachingConfig]
-> ReadPrec CachingConfig
-> ReadPrec [CachingConfig]
-> Read CachingConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CachingConfig]
$creadListPrec :: ReadPrec [CachingConfig]
readPrec :: ReadPrec CachingConfig
$creadPrec :: ReadPrec CachingConfig
readList :: ReadS [CachingConfig]
$creadList :: ReadS [CachingConfig]
readsPrec :: Int -> ReadS CachingConfig
$creadsPrec :: Int -> ReadS CachingConfig
Prelude.Read, Int -> CachingConfig -> ShowS
[CachingConfig] -> ShowS
CachingConfig -> String
(Int -> CachingConfig -> ShowS)
-> (CachingConfig -> String)
-> ([CachingConfig] -> ShowS)
-> Show CachingConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CachingConfig] -> ShowS
$cshowList :: [CachingConfig] -> ShowS
show :: CachingConfig -> String
$cshow :: CachingConfig -> String
showsPrec :: Int -> CachingConfig -> ShowS
$cshowsPrec :: Int -> CachingConfig -> ShowS
Prelude.Show, (forall x. CachingConfig -> Rep CachingConfig x)
-> (forall x. Rep CachingConfig x -> CachingConfig)
-> Generic CachingConfig
forall x. Rep CachingConfig x -> CachingConfig
forall x. CachingConfig -> Rep CachingConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CachingConfig x -> CachingConfig
$cfrom :: forall x. CachingConfig -> Rep CachingConfig x
Prelude.Generic)

-- |
-- Create a value of 'CachingConfig' 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:
--
-- 'ttl', 'cachingConfig_ttl' - The TTL in seconds for a resolver that has caching enabled.
--
-- Valid values are between 1 and 3600 seconds.
--
-- 'cachingKeys', 'cachingConfig_cachingKeys' - The caching keys for a resolver that has caching enabled.
--
-- Valid values are entries from the @$context.arguments@,
-- @$context.source@, and @$context.identity@ maps.
newCachingConfig ::
  CachingConfig
newCachingConfig :: CachingConfig
newCachingConfig =
  CachingConfig' :: Maybe Integer -> Maybe [Text] -> CachingConfig
CachingConfig'
    { $sel:ttl:CachingConfig' :: Maybe Integer
ttl = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:cachingKeys:CachingConfig' :: Maybe [Text]
cachingKeys = Maybe [Text]
forall a. Maybe a
Prelude.Nothing
    }

-- | The TTL in seconds for a resolver that has caching enabled.
--
-- Valid values are between 1 and 3600 seconds.
cachingConfig_ttl :: Lens.Lens' CachingConfig (Prelude.Maybe Prelude.Integer)
cachingConfig_ttl :: (Maybe Integer -> f (Maybe Integer))
-> CachingConfig -> f CachingConfig
cachingConfig_ttl = (CachingConfig -> Maybe Integer)
-> (CachingConfig -> Maybe Integer -> CachingConfig)
-> Lens CachingConfig CachingConfig (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachingConfig' {Maybe Integer
ttl :: Maybe Integer
$sel:ttl:CachingConfig' :: CachingConfig -> Maybe Integer
ttl} -> Maybe Integer
ttl) (\s :: CachingConfig
s@CachingConfig' {} Maybe Integer
a -> CachingConfig
s {$sel:ttl:CachingConfig' :: Maybe Integer
ttl = Maybe Integer
a} :: CachingConfig)

-- | The caching keys for a resolver that has caching enabled.
--
-- Valid values are entries from the @$context.arguments@,
-- @$context.source@, and @$context.identity@ maps.
cachingConfig_cachingKeys :: Lens.Lens' CachingConfig (Prelude.Maybe [Prelude.Text])
cachingConfig_cachingKeys :: (Maybe [Text] -> f (Maybe [Text]))
-> CachingConfig -> f CachingConfig
cachingConfig_cachingKeys = (CachingConfig -> Maybe [Text])
-> (CachingConfig -> Maybe [Text] -> CachingConfig)
-> Lens CachingConfig CachingConfig (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachingConfig' {Maybe [Text]
cachingKeys :: Maybe [Text]
$sel:cachingKeys:CachingConfig' :: CachingConfig -> Maybe [Text]
cachingKeys} -> Maybe [Text]
cachingKeys) (\s :: CachingConfig
s@CachingConfig' {} Maybe [Text]
a -> CachingConfig
s {$sel:cachingKeys:CachingConfig' :: Maybe [Text]
cachingKeys = Maybe [Text]
a} :: CachingConfig) ((Maybe [Text] -> f (Maybe [Text]))
 -> CachingConfig -> f CachingConfig)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> CachingConfig
-> f CachingConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON CachingConfig where
  parseJSON :: Value -> Parser CachingConfig
parseJSON =
    String
-> (Object -> Parser CachingConfig)
-> Value
-> Parser CachingConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CachingConfig"
      ( \Object
x ->
          Maybe Integer -> Maybe [Text] -> CachingConfig
CachingConfig'
            (Maybe Integer -> Maybe [Text] -> CachingConfig)
-> Parser (Maybe Integer) -> Parser (Maybe [Text] -> CachingConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ttl")
            Parser (Maybe [Text] -> CachingConfig)
-> Parser (Maybe [Text]) -> Parser CachingConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"cachingKeys" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable CachingConfig

instance Prelude.NFData CachingConfig

instance Core.ToJSON CachingConfig where
  toJSON :: CachingConfig -> Value
toJSON CachingConfig' {Maybe Integer
Maybe [Text]
cachingKeys :: Maybe [Text]
ttl :: Maybe Integer
$sel:cachingKeys:CachingConfig' :: CachingConfig -> Maybe [Text]
$sel:ttl:CachingConfig' :: CachingConfig -> Maybe Integer
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ttl" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
ttl,
            (Text
"cachingKeys" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
cachingKeys
          ]
      )