{-# 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.ValidateMatchmakingRuleSet
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Validates the syntax of a matchmaking rule or rule set. This operation
-- checks that the rule set is using syntactically correct JSON and that it
-- conforms to allowed property expressions. To validate syntax, provide a
-- rule set JSON string.
--
-- __Learn more__
--
-- -   <https://docs.aws.amazon.com/gamelift/latest/flexmatchguide/match-rulesets.html Build a rule set>
module Amazonka.GameLift.ValidateMatchmakingRuleSet
  ( -- * Creating a Request
    ValidateMatchmakingRuleSet (..),
    newValidateMatchmakingRuleSet,

    -- * Request Lenses
    validateMatchmakingRuleSet_ruleSetBody,

    -- * Destructuring the Response
    ValidateMatchmakingRuleSetResponse (..),
    newValidateMatchmakingRuleSetResponse,

    -- * Response Lenses
    validateMatchmakingRuleSetResponse_valid,
    validateMatchmakingRuleSetResponse_httpStatus,
  )
where

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

-- | /See:/ 'newValidateMatchmakingRuleSet' smart constructor.
data ValidateMatchmakingRuleSet = ValidateMatchmakingRuleSet'
  { -- | A collection of matchmaking rules to validate, formatted as a JSON
    -- string.
    ValidateMatchmakingRuleSet -> Text
ruleSetBody :: Prelude.Text
  }
  deriving (ValidateMatchmakingRuleSet -> ValidateMatchmakingRuleSet -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ValidateMatchmakingRuleSet -> ValidateMatchmakingRuleSet -> Bool
$c/= :: ValidateMatchmakingRuleSet -> ValidateMatchmakingRuleSet -> Bool
== :: ValidateMatchmakingRuleSet -> ValidateMatchmakingRuleSet -> Bool
$c== :: ValidateMatchmakingRuleSet -> ValidateMatchmakingRuleSet -> Bool
Prelude.Eq, ReadPrec [ValidateMatchmakingRuleSet]
ReadPrec ValidateMatchmakingRuleSet
Int -> ReadS ValidateMatchmakingRuleSet
ReadS [ValidateMatchmakingRuleSet]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ValidateMatchmakingRuleSet]
$creadListPrec :: ReadPrec [ValidateMatchmakingRuleSet]
readPrec :: ReadPrec ValidateMatchmakingRuleSet
$creadPrec :: ReadPrec ValidateMatchmakingRuleSet
readList :: ReadS [ValidateMatchmakingRuleSet]
$creadList :: ReadS [ValidateMatchmakingRuleSet]
readsPrec :: Int -> ReadS ValidateMatchmakingRuleSet
$creadsPrec :: Int -> ReadS ValidateMatchmakingRuleSet
Prelude.Read, Int -> ValidateMatchmakingRuleSet -> ShowS
[ValidateMatchmakingRuleSet] -> ShowS
ValidateMatchmakingRuleSet -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ValidateMatchmakingRuleSet] -> ShowS
$cshowList :: [ValidateMatchmakingRuleSet] -> ShowS
show :: ValidateMatchmakingRuleSet -> String
$cshow :: ValidateMatchmakingRuleSet -> String
showsPrec :: Int -> ValidateMatchmakingRuleSet -> ShowS
$cshowsPrec :: Int -> ValidateMatchmakingRuleSet -> ShowS
Prelude.Show, forall x.
Rep ValidateMatchmakingRuleSet x -> ValidateMatchmakingRuleSet
forall x.
ValidateMatchmakingRuleSet -> Rep ValidateMatchmakingRuleSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ValidateMatchmakingRuleSet x -> ValidateMatchmakingRuleSet
$cfrom :: forall x.
ValidateMatchmakingRuleSet -> Rep ValidateMatchmakingRuleSet x
Prelude.Generic)

-- |
-- Create a value of 'ValidateMatchmakingRuleSet' 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:
--
-- 'ruleSetBody', 'validateMatchmakingRuleSet_ruleSetBody' - A collection of matchmaking rules to validate, formatted as a JSON
-- string.
newValidateMatchmakingRuleSet ::
  -- | 'ruleSetBody'
  Prelude.Text ->
  ValidateMatchmakingRuleSet
newValidateMatchmakingRuleSet :: Text -> ValidateMatchmakingRuleSet
newValidateMatchmakingRuleSet Text
pRuleSetBody_ =
  ValidateMatchmakingRuleSet'
    { $sel:ruleSetBody:ValidateMatchmakingRuleSet' :: Text
ruleSetBody =
        Text
pRuleSetBody_
    }

-- | A collection of matchmaking rules to validate, formatted as a JSON
-- string.
validateMatchmakingRuleSet_ruleSetBody :: Lens.Lens' ValidateMatchmakingRuleSet Prelude.Text
validateMatchmakingRuleSet_ruleSetBody :: Lens' ValidateMatchmakingRuleSet Text
validateMatchmakingRuleSet_ruleSetBody = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ValidateMatchmakingRuleSet' {Text
ruleSetBody :: Text
$sel:ruleSetBody:ValidateMatchmakingRuleSet' :: ValidateMatchmakingRuleSet -> Text
ruleSetBody} -> Text
ruleSetBody) (\s :: ValidateMatchmakingRuleSet
s@ValidateMatchmakingRuleSet' {} Text
a -> ValidateMatchmakingRuleSet
s {$sel:ruleSetBody:ValidateMatchmakingRuleSet' :: Text
ruleSetBody = Text
a} :: ValidateMatchmakingRuleSet)

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

instance Prelude.Hashable ValidateMatchmakingRuleSet where
  hashWithSalt :: Int -> ValidateMatchmakingRuleSet -> Int
hashWithSalt Int
_salt ValidateMatchmakingRuleSet' {Text
ruleSetBody :: Text
$sel:ruleSetBody:ValidateMatchmakingRuleSet' :: ValidateMatchmakingRuleSet -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
ruleSetBody

instance Prelude.NFData ValidateMatchmakingRuleSet where
  rnf :: ValidateMatchmakingRuleSet -> ()
rnf ValidateMatchmakingRuleSet' {Text
ruleSetBody :: Text
$sel:ruleSetBody:ValidateMatchmakingRuleSet' :: ValidateMatchmakingRuleSet -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
ruleSetBody

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

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

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

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

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

-- |
-- Create a value of 'ValidateMatchmakingRuleSetResponse' 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:
--
-- 'valid', 'validateMatchmakingRuleSetResponse_valid' - A response indicating whether the rule set is valid.
--
-- 'httpStatus', 'validateMatchmakingRuleSetResponse_httpStatus' - The response's http status code.
newValidateMatchmakingRuleSetResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ValidateMatchmakingRuleSetResponse
newValidateMatchmakingRuleSetResponse :: Int -> ValidateMatchmakingRuleSetResponse
newValidateMatchmakingRuleSetResponse Int
pHttpStatus_ =
  ValidateMatchmakingRuleSetResponse'
    { $sel:valid:ValidateMatchmakingRuleSetResponse' :: Maybe Bool
valid =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ValidateMatchmakingRuleSetResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A response indicating whether the rule set is valid.
validateMatchmakingRuleSetResponse_valid :: Lens.Lens' ValidateMatchmakingRuleSetResponse (Prelude.Maybe Prelude.Bool)
validateMatchmakingRuleSetResponse_valid :: Lens' ValidateMatchmakingRuleSetResponse (Maybe Bool)
validateMatchmakingRuleSetResponse_valid = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ValidateMatchmakingRuleSetResponse' {Maybe Bool
valid :: Maybe Bool
$sel:valid:ValidateMatchmakingRuleSetResponse' :: ValidateMatchmakingRuleSetResponse -> Maybe Bool
valid} -> Maybe Bool
valid) (\s :: ValidateMatchmakingRuleSetResponse
s@ValidateMatchmakingRuleSetResponse' {} Maybe Bool
a -> ValidateMatchmakingRuleSetResponse
s {$sel:valid:ValidateMatchmakingRuleSetResponse' :: Maybe Bool
valid = Maybe Bool
a} :: ValidateMatchmakingRuleSetResponse)

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

instance
  Prelude.NFData
    ValidateMatchmakingRuleSetResponse
  where
  rnf :: ValidateMatchmakingRuleSetResponse -> ()
rnf ValidateMatchmakingRuleSetResponse' {Int
Maybe Bool
httpStatus :: Int
valid :: Maybe Bool
$sel:httpStatus:ValidateMatchmakingRuleSetResponse' :: ValidateMatchmakingRuleSetResponse -> Int
$sel:valid:ValidateMatchmakingRuleSetResponse' :: ValidateMatchmakingRuleSetResponse -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
valid
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus