{-# 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.Evidently.TestSegmentPattern
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Use this operation to test a rules pattern that you plan to use to
-- create an audience segment. For more information about segments, see
-- <https://docs.aws.amazon.com/cloudwatchevidently/latest/APIReference/API_CreateSegment.html CreateSegment>.
module Amazonka.Evidently.TestSegmentPattern
  ( -- * Creating a Request
    TestSegmentPattern (..),
    newTestSegmentPattern,

    -- * Request Lenses
    testSegmentPattern_pattern,
    testSegmentPattern_payload,

    -- * Destructuring the Response
    TestSegmentPatternResponse (..),
    newTestSegmentPatternResponse,

    -- * Response Lenses
    testSegmentPatternResponse_httpStatus,
    testSegmentPatternResponse_match,
  )
where

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

-- | /See:/ 'newTestSegmentPattern' smart constructor.
data TestSegmentPattern = TestSegmentPattern'
  { -- | The pattern to test.
    TestSegmentPattern -> Text
pattern' :: Prelude.Text,
    -- | A sample @evaluationContext@ JSON block to test against the specified
    -- pattern.
    TestSegmentPattern -> Text
payload :: Prelude.Text
  }
  deriving (TestSegmentPattern -> TestSegmentPattern -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TestSegmentPattern -> TestSegmentPattern -> Bool
$c/= :: TestSegmentPattern -> TestSegmentPattern -> Bool
== :: TestSegmentPattern -> TestSegmentPattern -> Bool
$c== :: TestSegmentPattern -> TestSegmentPattern -> Bool
Prelude.Eq, ReadPrec [TestSegmentPattern]
ReadPrec TestSegmentPattern
Int -> ReadS TestSegmentPattern
ReadS [TestSegmentPattern]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TestSegmentPattern]
$creadListPrec :: ReadPrec [TestSegmentPattern]
readPrec :: ReadPrec TestSegmentPattern
$creadPrec :: ReadPrec TestSegmentPattern
readList :: ReadS [TestSegmentPattern]
$creadList :: ReadS [TestSegmentPattern]
readsPrec :: Int -> ReadS TestSegmentPattern
$creadsPrec :: Int -> ReadS TestSegmentPattern
Prelude.Read, Int -> TestSegmentPattern -> ShowS
[TestSegmentPattern] -> ShowS
TestSegmentPattern -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TestSegmentPattern] -> ShowS
$cshowList :: [TestSegmentPattern] -> ShowS
show :: TestSegmentPattern -> String
$cshow :: TestSegmentPattern -> String
showsPrec :: Int -> TestSegmentPattern -> ShowS
$cshowsPrec :: Int -> TestSegmentPattern -> ShowS
Prelude.Show, forall x. Rep TestSegmentPattern x -> TestSegmentPattern
forall x. TestSegmentPattern -> Rep TestSegmentPattern x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TestSegmentPattern x -> TestSegmentPattern
$cfrom :: forall x. TestSegmentPattern -> Rep TestSegmentPattern x
Prelude.Generic)

-- |
-- Create a value of 'TestSegmentPattern' 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:
--
-- 'pattern'', 'testSegmentPattern_pattern' - The pattern to test.
--
-- 'payload', 'testSegmentPattern_payload' - A sample @evaluationContext@ JSON block to test against the specified
-- pattern.
newTestSegmentPattern ::
  -- | 'pattern''
  Prelude.Text ->
  -- | 'payload'
  Prelude.Text ->
  TestSegmentPattern
newTestSegmentPattern :: Text -> Text -> TestSegmentPattern
newTestSegmentPattern Text
pPattern_ Text
pPayload_ =
  TestSegmentPattern'
    { $sel:pattern':TestSegmentPattern' :: Text
pattern' = Text
pPattern_,
      $sel:payload:TestSegmentPattern' :: Text
payload = Text
pPayload_
    }

-- | The pattern to test.
testSegmentPattern_pattern :: Lens.Lens' TestSegmentPattern Prelude.Text
testSegmentPattern_pattern :: Lens' TestSegmentPattern Text
testSegmentPattern_pattern = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestSegmentPattern' {Text
pattern' :: Text
$sel:pattern':TestSegmentPattern' :: TestSegmentPattern -> Text
pattern'} -> Text
pattern') (\s :: TestSegmentPattern
s@TestSegmentPattern' {} Text
a -> TestSegmentPattern
s {$sel:pattern':TestSegmentPattern' :: Text
pattern' = Text
a} :: TestSegmentPattern)

-- | A sample @evaluationContext@ JSON block to test against the specified
-- pattern.
testSegmentPattern_payload :: Lens.Lens' TestSegmentPattern Prelude.Text
testSegmentPattern_payload :: Lens' TestSegmentPattern Text
testSegmentPattern_payload = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestSegmentPattern' {Text
payload :: Text
$sel:payload:TestSegmentPattern' :: TestSegmentPattern -> Text
payload} -> Text
payload) (\s :: TestSegmentPattern
s@TestSegmentPattern' {} Text
a -> TestSegmentPattern
s {$sel:payload:TestSegmentPattern' :: Text
payload = Text
a} :: TestSegmentPattern)

instance Core.AWSRequest TestSegmentPattern where
  type
    AWSResponse TestSegmentPattern =
      TestSegmentPatternResponse
  request :: (Service -> Service)
-> TestSegmentPattern -> Request TestSegmentPattern
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 TestSegmentPattern
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse TestSegmentPattern)))
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 ->
          Int -> Bool -> TestSegmentPatternResponse
TestSegmentPatternResponse'
            forall (f :: * -> *) a b. Functor 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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"match")
      )

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

instance Prelude.NFData TestSegmentPattern where
  rnf :: TestSegmentPattern -> ()
rnf TestSegmentPattern' {Text
payload :: Text
pattern' :: Text
$sel:payload:TestSegmentPattern' :: TestSegmentPattern -> Text
$sel:pattern':TestSegmentPattern' :: TestSegmentPattern -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
pattern'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
payload

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

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

instance Data.ToPath TestSegmentPattern where
  toPath :: TestSegmentPattern -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/test-segment-pattern"

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

-- | /See:/ 'newTestSegmentPatternResponse' smart constructor.
data TestSegmentPatternResponse = TestSegmentPatternResponse'
  { -- | The response's http status code.
    TestSegmentPatternResponse -> Int
httpStatus :: Prelude.Int,
    -- | Returns @true@ if the pattern matches the payload.
    TestSegmentPatternResponse -> Bool
match :: Prelude.Bool
  }
  deriving (TestSegmentPatternResponse -> TestSegmentPatternResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TestSegmentPatternResponse -> TestSegmentPatternResponse -> Bool
$c/= :: TestSegmentPatternResponse -> TestSegmentPatternResponse -> Bool
== :: TestSegmentPatternResponse -> TestSegmentPatternResponse -> Bool
$c== :: TestSegmentPatternResponse -> TestSegmentPatternResponse -> Bool
Prelude.Eq, ReadPrec [TestSegmentPatternResponse]
ReadPrec TestSegmentPatternResponse
Int -> ReadS TestSegmentPatternResponse
ReadS [TestSegmentPatternResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TestSegmentPatternResponse]
$creadListPrec :: ReadPrec [TestSegmentPatternResponse]
readPrec :: ReadPrec TestSegmentPatternResponse
$creadPrec :: ReadPrec TestSegmentPatternResponse
readList :: ReadS [TestSegmentPatternResponse]
$creadList :: ReadS [TestSegmentPatternResponse]
readsPrec :: Int -> ReadS TestSegmentPatternResponse
$creadsPrec :: Int -> ReadS TestSegmentPatternResponse
Prelude.Read, Int -> TestSegmentPatternResponse -> ShowS
[TestSegmentPatternResponse] -> ShowS
TestSegmentPatternResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TestSegmentPatternResponse] -> ShowS
$cshowList :: [TestSegmentPatternResponse] -> ShowS
show :: TestSegmentPatternResponse -> String
$cshow :: TestSegmentPatternResponse -> String
showsPrec :: Int -> TestSegmentPatternResponse -> ShowS
$cshowsPrec :: Int -> TestSegmentPatternResponse -> ShowS
Prelude.Show, forall x.
Rep TestSegmentPatternResponse x -> TestSegmentPatternResponse
forall x.
TestSegmentPatternResponse -> Rep TestSegmentPatternResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TestSegmentPatternResponse x -> TestSegmentPatternResponse
$cfrom :: forall x.
TestSegmentPatternResponse -> Rep TestSegmentPatternResponse x
Prelude.Generic)

-- |
-- Create a value of 'TestSegmentPatternResponse' 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:
--
-- 'httpStatus', 'testSegmentPatternResponse_httpStatus' - The response's http status code.
--
-- 'match', 'testSegmentPatternResponse_match' - Returns @true@ if the pattern matches the payload.
newTestSegmentPatternResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'match'
  Prelude.Bool ->
  TestSegmentPatternResponse
newTestSegmentPatternResponse :: Int -> Bool -> TestSegmentPatternResponse
newTestSegmentPatternResponse Int
pHttpStatus_ Bool
pMatch_ =
  TestSegmentPatternResponse'
    { $sel:httpStatus:TestSegmentPatternResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:match:TestSegmentPatternResponse' :: Bool
match = Bool
pMatch_
    }

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

-- | Returns @true@ if the pattern matches the payload.
testSegmentPatternResponse_match :: Lens.Lens' TestSegmentPatternResponse Prelude.Bool
testSegmentPatternResponse_match :: Lens' TestSegmentPatternResponse Bool
testSegmentPatternResponse_match = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestSegmentPatternResponse' {Bool
match :: Bool
$sel:match:TestSegmentPatternResponse' :: TestSegmentPatternResponse -> Bool
match} -> Bool
match) (\s :: TestSegmentPatternResponse
s@TestSegmentPatternResponse' {} Bool
a -> TestSegmentPatternResponse
s {$sel:match:TestSegmentPatternResponse' :: Bool
match = Bool
a} :: TestSegmentPatternResponse)

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