{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.GameLift.DescribeScript
-- 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)
--
-- Retrieves properties for a Realtime script.
--
-- To request a script record, specify the script ID. If successful, an
-- object containing the script properties is returned.
--
-- __Learn more__
--
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/realtime-intro.html Amazon GameLift Realtime Servers>
--
-- __Related actions__
--
-- CreateScript | ListScripts | DescribeScript | UpdateScript |
-- DeleteScript |
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets All APIs by task>
module Amazonka.GameLift.DescribeScript
  ( -- * Creating a Request
    DescribeScript (..),
    newDescribeScript,

    -- * Request Lenses
    describeScript_scriptId,

    -- * Destructuring the Response
    DescribeScriptResponse (..),
    newDescribeScriptResponse,

    -- * Response Lenses
    describeScriptResponse_script,
    describeScriptResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.GameLift.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDescribeScript' smart constructor.
data DescribeScript = DescribeScript'
  { -- | A unique identifier for the Realtime script to retrieve properties for.
    -- You can use either the script ID or ARN value.
    DescribeScript -> Text
scriptId :: Prelude.Text
  }
  deriving (DescribeScript -> DescribeScript -> Bool
(DescribeScript -> DescribeScript -> Bool)
-> (DescribeScript -> DescribeScript -> Bool) -> Eq DescribeScript
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeScript -> DescribeScript -> Bool
$c/= :: DescribeScript -> DescribeScript -> Bool
== :: DescribeScript -> DescribeScript -> Bool
$c== :: DescribeScript -> DescribeScript -> Bool
Prelude.Eq, ReadPrec [DescribeScript]
ReadPrec DescribeScript
Int -> ReadS DescribeScript
ReadS [DescribeScript]
(Int -> ReadS DescribeScript)
-> ReadS [DescribeScript]
-> ReadPrec DescribeScript
-> ReadPrec [DescribeScript]
-> Read DescribeScript
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeScript]
$creadListPrec :: ReadPrec [DescribeScript]
readPrec :: ReadPrec DescribeScript
$creadPrec :: ReadPrec DescribeScript
readList :: ReadS [DescribeScript]
$creadList :: ReadS [DescribeScript]
readsPrec :: Int -> ReadS DescribeScript
$creadsPrec :: Int -> ReadS DescribeScript
Prelude.Read, Int -> DescribeScript -> ShowS
[DescribeScript] -> ShowS
DescribeScript -> String
(Int -> DescribeScript -> ShowS)
-> (DescribeScript -> String)
-> ([DescribeScript] -> ShowS)
-> Show DescribeScript
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeScript] -> ShowS
$cshowList :: [DescribeScript] -> ShowS
show :: DescribeScript -> String
$cshow :: DescribeScript -> String
showsPrec :: Int -> DescribeScript -> ShowS
$cshowsPrec :: Int -> DescribeScript -> ShowS
Prelude.Show, (forall x. DescribeScript -> Rep DescribeScript x)
-> (forall x. Rep DescribeScript x -> DescribeScript)
-> Generic DescribeScript
forall x. Rep DescribeScript x -> DescribeScript
forall x. DescribeScript -> Rep DescribeScript x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeScript x -> DescribeScript
$cfrom :: forall x. DescribeScript -> Rep DescribeScript x
Prelude.Generic)

-- |
-- Create a value of 'DescribeScript' 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:
--
-- 'scriptId', 'describeScript_scriptId' - A unique identifier for the Realtime script to retrieve properties for.
-- You can use either the script ID or ARN value.
newDescribeScript ::
  -- | 'scriptId'
  Prelude.Text ->
  DescribeScript
newDescribeScript :: Text -> DescribeScript
newDescribeScript Text
pScriptId_ =
  DescribeScript' :: Text -> DescribeScript
DescribeScript' {$sel:scriptId:DescribeScript' :: Text
scriptId = Text
pScriptId_}

-- | A unique identifier for the Realtime script to retrieve properties for.
-- You can use either the script ID or ARN value.
describeScript_scriptId :: Lens.Lens' DescribeScript Prelude.Text
describeScript_scriptId :: (Text -> f Text) -> DescribeScript -> f DescribeScript
describeScript_scriptId = (DescribeScript -> Text)
-> (DescribeScript -> Text -> DescribeScript)
-> Lens DescribeScript DescribeScript Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeScript' {Text
scriptId :: Text
$sel:scriptId:DescribeScript' :: DescribeScript -> Text
scriptId} -> Text
scriptId) (\s :: DescribeScript
s@DescribeScript' {} Text
a -> DescribeScript
s {$sel:scriptId:DescribeScript' :: Text
scriptId = Text
a} :: DescribeScript)

instance Core.AWSRequest DescribeScript where
  type
    AWSResponse DescribeScript =
      DescribeScriptResponse
  request :: DescribeScript -> Request DescribeScript
request = Service -> DescribeScript -> Request DescribeScript
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeScript
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeScript)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DescribeScript))
-> Logger
-> Service
-> Proxy DescribeScript
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeScript)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Script -> Int -> DescribeScriptResponse
DescribeScriptResponse'
            (Maybe Script -> Int -> DescribeScriptResponse)
-> Either String (Maybe Script)
-> Either String (Int -> DescribeScriptResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Script)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Script")
            Either String (Int -> DescribeScriptResponse)
-> Either String Int -> Either String DescribeScriptResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable DescribeScript

instance Prelude.NFData DescribeScript

instance Core.ToHeaders DescribeScript where
  toHeaders :: DescribeScript -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeScript -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"GameLift.DescribeScript" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON DescribeScript where
  toJSON :: DescribeScript -> Value
toJSON DescribeScript' {Text
scriptId :: Text
$sel:scriptId:DescribeScript' :: DescribeScript -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ScriptId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
scriptId)]
      )

instance Core.ToPath DescribeScript where
  toPath :: DescribeScript -> ByteString
toPath = ByteString -> DescribeScript -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery DescribeScript where
  toQuery :: DescribeScript -> QueryString
toQuery = QueryString -> DescribeScript -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newDescribeScriptResponse' smart constructor.
data DescribeScriptResponse = DescribeScriptResponse'
  { -- | A set of properties describing the requested script.
    DescribeScriptResponse -> Maybe Script
script :: Prelude.Maybe Script,
    -- | The response's http status code.
    DescribeScriptResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeScriptResponse -> DescribeScriptResponse -> Bool
(DescribeScriptResponse -> DescribeScriptResponse -> Bool)
-> (DescribeScriptResponse -> DescribeScriptResponse -> Bool)
-> Eq DescribeScriptResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeScriptResponse -> DescribeScriptResponse -> Bool
$c/= :: DescribeScriptResponse -> DescribeScriptResponse -> Bool
== :: DescribeScriptResponse -> DescribeScriptResponse -> Bool
$c== :: DescribeScriptResponse -> DescribeScriptResponse -> Bool
Prelude.Eq, ReadPrec [DescribeScriptResponse]
ReadPrec DescribeScriptResponse
Int -> ReadS DescribeScriptResponse
ReadS [DescribeScriptResponse]
(Int -> ReadS DescribeScriptResponse)
-> ReadS [DescribeScriptResponse]
-> ReadPrec DescribeScriptResponse
-> ReadPrec [DescribeScriptResponse]
-> Read DescribeScriptResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeScriptResponse]
$creadListPrec :: ReadPrec [DescribeScriptResponse]
readPrec :: ReadPrec DescribeScriptResponse
$creadPrec :: ReadPrec DescribeScriptResponse
readList :: ReadS [DescribeScriptResponse]
$creadList :: ReadS [DescribeScriptResponse]
readsPrec :: Int -> ReadS DescribeScriptResponse
$creadsPrec :: Int -> ReadS DescribeScriptResponse
Prelude.Read, Int -> DescribeScriptResponse -> ShowS
[DescribeScriptResponse] -> ShowS
DescribeScriptResponse -> String
(Int -> DescribeScriptResponse -> ShowS)
-> (DescribeScriptResponse -> String)
-> ([DescribeScriptResponse] -> ShowS)
-> Show DescribeScriptResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeScriptResponse] -> ShowS
$cshowList :: [DescribeScriptResponse] -> ShowS
show :: DescribeScriptResponse -> String
$cshow :: DescribeScriptResponse -> String
showsPrec :: Int -> DescribeScriptResponse -> ShowS
$cshowsPrec :: Int -> DescribeScriptResponse -> ShowS
Prelude.Show, (forall x. DescribeScriptResponse -> Rep DescribeScriptResponse x)
-> (forall x.
    Rep DescribeScriptResponse x -> DescribeScriptResponse)
-> Generic DescribeScriptResponse
forall x. Rep DescribeScriptResponse x -> DescribeScriptResponse
forall x. DescribeScriptResponse -> Rep DescribeScriptResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeScriptResponse x -> DescribeScriptResponse
$cfrom :: forall x. DescribeScriptResponse -> Rep DescribeScriptResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeScriptResponse' 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:
--
-- 'script', 'describeScriptResponse_script' - A set of properties describing the requested script.
--
-- 'httpStatus', 'describeScriptResponse_httpStatus' - The response's http status code.
newDescribeScriptResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeScriptResponse
newDescribeScriptResponse :: Int -> DescribeScriptResponse
newDescribeScriptResponse Int
pHttpStatus_ =
  DescribeScriptResponse' :: Maybe Script -> Int -> DescribeScriptResponse
DescribeScriptResponse'
    { $sel:script:DescribeScriptResponse' :: Maybe Script
script = Maybe Script
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeScriptResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A set of properties describing the requested script.
describeScriptResponse_script :: Lens.Lens' DescribeScriptResponse (Prelude.Maybe Script)
describeScriptResponse_script :: (Maybe Script -> f (Maybe Script))
-> DescribeScriptResponse -> f DescribeScriptResponse
describeScriptResponse_script = (DescribeScriptResponse -> Maybe Script)
-> (DescribeScriptResponse
    -> Maybe Script -> DescribeScriptResponse)
-> Lens
     DescribeScriptResponse
     DescribeScriptResponse
     (Maybe Script)
     (Maybe Script)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeScriptResponse' {Maybe Script
script :: Maybe Script
$sel:script:DescribeScriptResponse' :: DescribeScriptResponse -> Maybe Script
script} -> Maybe Script
script) (\s :: DescribeScriptResponse
s@DescribeScriptResponse' {} Maybe Script
a -> DescribeScriptResponse
s {$sel:script:DescribeScriptResponse' :: Maybe Script
script = Maybe Script
a} :: DescribeScriptResponse)

-- | The response's http status code.
describeScriptResponse_httpStatus :: Lens.Lens' DescribeScriptResponse Prelude.Int
describeScriptResponse_httpStatus :: (Int -> f Int)
-> DescribeScriptResponse -> f DescribeScriptResponse
describeScriptResponse_httpStatus = (DescribeScriptResponse -> Int)
-> (DescribeScriptResponse -> Int -> DescribeScriptResponse)
-> Lens DescribeScriptResponse DescribeScriptResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeScriptResponse' {Int
httpStatus :: Int
$sel:httpStatus:DescribeScriptResponse' :: DescribeScriptResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DescribeScriptResponse
s@DescribeScriptResponse' {} Int
a -> DescribeScriptResponse
s {$sel:httpStatus:DescribeScriptResponse' :: Int
httpStatus = Int
a} :: DescribeScriptResponse)

instance Prelude.NFData DescribeScriptResponse