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

import Amazonka.AppSync.Types.RuntimeName
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 a runtime used by an Amazon Web Services AppSync pipeline
-- resolver or Amazon Web Services AppSync function. Specifies the name and
-- version of the runtime to use. Note that if a runtime is specified, code
-- must also be specified.
--
-- /See:/ 'newAppSyncRuntime' smart constructor.
data AppSyncRuntime = AppSyncRuntime'
  { -- | The @name@ of the runtime to use. Currently, the only allowed value is
    -- @APPSYNC_JS@.
    AppSyncRuntime -> RuntimeName
name :: RuntimeName,
    -- | The @version@ of the runtime to use. Currently, the only allowed version
    -- is @1.0.0@.
    AppSyncRuntime -> Text
runtimeVersion :: Prelude.Text
  }
  deriving (AppSyncRuntime -> AppSyncRuntime -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AppSyncRuntime -> AppSyncRuntime -> Bool
$c/= :: AppSyncRuntime -> AppSyncRuntime -> Bool
== :: AppSyncRuntime -> AppSyncRuntime -> Bool
$c== :: AppSyncRuntime -> AppSyncRuntime -> Bool
Prelude.Eq, ReadPrec [AppSyncRuntime]
ReadPrec AppSyncRuntime
Int -> ReadS AppSyncRuntime
ReadS [AppSyncRuntime]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AppSyncRuntime]
$creadListPrec :: ReadPrec [AppSyncRuntime]
readPrec :: ReadPrec AppSyncRuntime
$creadPrec :: ReadPrec AppSyncRuntime
readList :: ReadS [AppSyncRuntime]
$creadList :: ReadS [AppSyncRuntime]
readsPrec :: Int -> ReadS AppSyncRuntime
$creadsPrec :: Int -> ReadS AppSyncRuntime
Prelude.Read, Int -> AppSyncRuntime -> ShowS
[AppSyncRuntime] -> ShowS
AppSyncRuntime -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AppSyncRuntime] -> ShowS
$cshowList :: [AppSyncRuntime] -> ShowS
show :: AppSyncRuntime -> String
$cshow :: AppSyncRuntime -> String
showsPrec :: Int -> AppSyncRuntime -> ShowS
$cshowsPrec :: Int -> AppSyncRuntime -> ShowS
Prelude.Show, forall x. Rep AppSyncRuntime x -> AppSyncRuntime
forall x. AppSyncRuntime -> Rep AppSyncRuntime x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AppSyncRuntime x -> AppSyncRuntime
$cfrom :: forall x. AppSyncRuntime -> Rep AppSyncRuntime x
Prelude.Generic)

-- |
-- Create a value of 'AppSyncRuntime' 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:
--
-- 'name', 'appSyncRuntime_name' - The @name@ of the runtime to use. Currently, the only allowed value is
-- @APPSYNC_JS@.
--
-- 'runtimeVersion', 'appSyncRuntime_runtimeVersion' - The @version@ of the runtime to use. Currently, the only allowed version
-- is @1.0.0@.
newAppSyncRuntime ::
  -- | 'name'
  RuntimeName ->
  -- | 'runtimeVersion'
  Prelude.Text ->
  AppSyncRuntime
newAppSyncRuntime :: RuntimeName -> Text -> AppSyncRuntime
newAppSyncRuntime RuntimeName
pName_ Text
pRuntimeVersion_ =
  AppSyncRuntime'
    { $sel:name:AppSyncRuntime' :: RuntimeName
name = RuntimeName
pName_,
      $sel:runtimeVersion:AppSyncRuntime' :: Text
runtimeVersion = Text
pRuntimeVersion_
    }

-- | The @name@ of the runtime to use. Currently, the only allowed value is
-- @APPSYNC_JS@.
appSyncRuntime_name :: Lens.Lens' AppSyncRuntime RuntimeName
appSyncRuntime_name :: Lens' AppSyncRuntime RuntimeName
appSyncRuntime_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AppSyncRuntime' {RuntimeName
name :: RuntimeName
$sel:name:AppSyncRuntime' :: AppSyncRuntime -> RuntimeName
name} -> RuntimeName
name) (\s :: AppSyncRuntime
s@AppSyncRuntime' {} RuntimeName
a -> AppSyncRuntime
s {$sel:name:AppSyncRuntime' :: RuntimeName
name = RuntimeName
a} :: AppSyncRuntime)

-- | The @version@ of the runtime to use. Currently, the only allowed version
-- is @1.0.0@.
appSyncRuntime_runtimeVersion :: Lens.Lens' AppSyncRuntime Prelude.Text
appSyncRuntime_runtimeVersion :: Lens' AppSyncRuntime Text
appSyncRuntime_runtimeVersion = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AppSyncRuntime' {Text
runtimeVersion :: Text
$sel:runtimeVersion:AppSyncRuntime' :: AppSyncRuntime -> Text
runtimeVersion} -> Text
runtimeVersion) (\s :: AppSyncRuntime
s@AppSyncRuntime' {} Text
a -> AppSyncRuntime
s {$sel:runtimeVersion:AppSyncRuntime' :: Text
runtimeVersion = Text
a} :: AppSyncRuntime)

instance Data.FromJSON AppSyncRuntime where
  parseJSON :: Value -> Parser AppSyncRuntime
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AppSyncRuntime"
      ( \Object
x ->
          RuntimeName -> Text -> AppSyncRuntime
AppSyncRuntime'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"name")
            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
"runtimeVersion")
      )

instance Prelude.Hashable AppSyncRuntime where
  hashWithSalt :: Int -> AppSyncRuntime -> Int
hashWithSalt Int
_salt AppSyncRuntime' {Text
RuntimeName
runtimeVersion :: Text
name :: RuntimeName
$sel:runtimeVersion:AppSyncRuntime' :: AppSyncRuntime -> Text
$sel:name:AppSyncRuntime' :: AppSyncRuntime -> RuntimeName
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` RuntimeName
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
runtimeVersion

instance Prelude.NFData AppSyncRuntime where
  rnf :: AppSyncRuntime -> ()
rnf AppSyncRuntime' {Text
RuntimeName
runtimeVersion :: Text
name :: RuntimeName
$sel:runtimeVersion:AppSyncRuntime' :: AppSyncRuntime -> Text
$sel:name:AppSyncRuntime' :: AppSyncRuntime -> RuntimeName
..} =
    forall a. NFData a => a -> ()
Prelude.rnf RuntimeName
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
runtimeVersion

instance Data.ToJSON AppSyncRuntime where
  toJSON :: AppSyncRuntime -> Value
toJSON AppSyncRuntime' {Text
RuntimeName
runtimeVersion :: Text
name :: RuntimeName
$sel:runtimeVersion:AppSyncRuntime' :: AppSyncRuntime -> Text
$sel:name:AppSyncRuntime' :: AppSyncRuntime -> RuntimeName
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= RuntimeName
name),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"runtimeVersion" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
runtimeVersion)
          ]
      )