{-# 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-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)
--
-- 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>
--
-- __Related actions__
--
-- CreateMatchmakingConfiguration | DescribeMatchmakingConfigurations |
-- UpdateMatchmakingConfiguration | DeleteMatchmakingConfiguration |
-- CreateMatchmakingRuleSet | DescribeMatchmakingRuleSets |
-- ValidateMatchmakingRuleSet | DeleteMatchmakingRuleSet |
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets All APIs by task>
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 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

-- | Represents the input for a request operation.
--
-- /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
(ValidateMatchmakingRuleSet -> ValidateMatchmakingRuleSet -> Bool)
-> (ValidateMatchmakingRuleSet
    -> ValidateMatchmakingRuleSet -> Bool)
-> Eq ValidateMatchmakingRuleSet
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]
(Int -> ReadS ValidateMatchmakingRuleSet)
-> ReadS [ValidateMatchmakingRuleSet]
-> ReadPrec ValidateMatchmakingRuleSet
-> ReadPrec [ValidateMatchmakingRuleSet]
-> Read 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
(Int -> ValidateMatchmakingRuleSet -> ShowS)
-> (ValidateMatchmakingRuleSet -> String)
-> ([ValidateMatchmakingRuleSet] -> ShowS)
-> Show ValidateMatchmakingRuleSet
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.
 ValidateMatchmakingRuleSet -> Rep ValidateMatchmakingRuleSet x)
-> (forall x.
    Rep ValidateMatchmakingRuleSet x -> ValidateMatchmakingRuleSet)
-> Generic ValidateMatchmakingRuleSet
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' :: Text -> ValidateMatchmakingRuleSet
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 :: (Text -> f Text)
-> ValidateMatchmakingRuleSet -> f ValidateMatchmakingRuleSet
validateMatchmakingRuleSet_ruleSetBody = (ValidateMatchmakingRuleSet -> Text)
-> (ValidateMatchmakingRuleSet
    -> Text -> ValidateMatchmakingRuleSet)
-> Lens
     ValidateMatchmakingRuleSet ValidateMatchmakingRuleSet Text Text
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 :: ValidateMatchmakingRuleSet -> Request ValidateMatchmakingRuleSet
request = Service
-> ValidateMatchmakingRuleSet -> Request ValidateMatchmakingRuleSet
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ValidateMatchmakingRuleSet
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ValidateMatchmakingRuleSet)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ValidateMatchmakingRuleSet))
-> Logger
-> Service
-> Proxy ValidateMatchmakingRuleSet
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ValidateMatchmakingRuleSet)))
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 Bool -> Int -> ValidateMatchmakingRuleSetResponse
ValidateMatchmakingRuleSetResponse'
            (Maybe Bool -> Int -> ValidateMatchmakingRuleSetResponse)
-> Either String (Maybe Bool)
-> Either String (Int -> ValidateMatchmakingRuleSetResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Valid")
            Either String (Int -> ValidateMatchmakingRuleSetResponse)
-> Either String Int
-> Either String ValidateMatchmakingRuleSetResponse
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 ValidateMatchmakingRuleSet

instance Prelude.NFData ValidateMatchmakingRuleSet

instance Core.ToHeaders ValidateMatchmakingRuleSet where
  toHeaders :: ValidateMatchmakingRuleSet -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ValidateMatchmakingRuleSet -> 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.ValidateMatchmakingRuleSet" ::
                          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 ValidateMatchmakingRuleSet where
  toJSON :: ValidateMatchmakingRuleSet -> Value
toJSON ValidateMatchmakingRuleSet' {Text
ruleSetBody :: Text
$sel:ruleSetBody:ValidateMatchmakingRuleSet' :: ValidateMatchmakingRuleSet -> 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
"RuleSetBody" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
ruleSetBody)]
      )

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

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

-- | Represents the returned data in response to a request operation.
--
-- /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
(ValidateMatchmakingRuleSetResponse
 -> ValidateMatchmakingRuleSetResponse -> Bool)
-> (ValidateMatchmakingRuleSetResponse
    -> ValidateMatchmakingRuleSetResponse -> Bool)
-> Eq ValidateMatchmakingRuleSetResponse
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]
(Int -> ReadS ValidateMatchmakingRuleSetResponse)
-> ReadS [ValidateMatchmakingRuleSetResponse]
-> ReadPrec ValidateMatchmakingRuleSetResponse
-> ReadPrec [ValidateMatchmakingRuleSetResponse]
-> Read 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
(Int -> ValidateMatchmakingRuleSetResponse -> ShowS)
-> (ValidateMatchmakingRuleSetResponse -> String)
-> ([ValidateMatchmakingRuleSetResponse] -> ShowS)
-> Show ValidateMatchmakingRuleSetResponse
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.
 ValidateMatchmakingRuleSetResponse
 -> Rep ValidateMatchmakingRuleSetResponse x)
-> (forall x.
    Rep ValidateMatchmakingRuleSetResponse x
    -> ValidateMatchmakingRuleSetResponse)
-> Generic ValidateMatchmakingRuleSetResponse
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' :: Maybe Bool -> Int -> ValidateMatchmakingRuleSetResponse
ValidateMatchmakingRuleSetResponse'
    { $sel:valid:ValidateMatchmakingRuleSetResponse' :: Maybe Bool
valid =
        Maybe Bool
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 :: (Maybe Bool -> f (Maybe Bool))
-> ValidateMatchmakingRuleSetResponse
-> f ValidateMatchmakingRuleSetResponse
validateMatchmakingRuleSetResponse_valid = (ValidateMatchmakingRuleSetResponse -> Maybe Bool)
-> (ValidateMatchmakingRuleSetResponse
    -> Maybe Bool -> ValidateMatchmakingRuleSetResponse)
-> Lens
     ValidateMatchmakingRuleSetResponse
     ValidateMatchmakingRuleSetResponse
     (Maybe Bool)
     (Maybe Bool)
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 :: (Int -> f Int)
-> ValidateMatchmakingRuleSetResponse
-> f ValidateMatchmakingRuleSetResponse
validateMatchmakingRuleSetResponse_httpStatus = (ValidateMatchmakingRuleSetResponse -> Int)
-> (ValidateMatchmakingRuleSetResponse
    -> Int -> ValidateMatchmakingRuleSetResponse)
-> Lens
     ValidateMatchmakingRuleSetResponse
     ValidateMatchmakingRuleSetResponse
     Int
     Int
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