{-# 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.ELBV2.Types.Matcher
-- 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.ELBV2.Types.Matcher where

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

-- | The codes to use when checking for a successful response from a target.
-- If the protocol version is gRPC, these are gRPC codes. Otherwise, these
-- are HTTP codes.
--
-- /See:/ 'newMatcher' smart constructor.
data Matcher = Matcher'
  { -- | You can specify values between 0 and 99. You can specify multiple values
    -- (for example, \"0,1\") or a range of values (for example, \"0-5\"). The
    -- default value is 12.
    Matcher -> Maybe Text
grpcCode :: Prelude.Maybe Prelude.Text,
    -- | For Application Load Balancers, you can specify values between 200 and
    -- 499, with the default value being 200. You can specify multiple values
    -- (for example, \"200,202\") or a range of values (for example,
    -- \"200-299\").
    --
    -- For Network Load Balancers, you can specify values between 200 and 599,
    -- with the default value being 200-399. You can specify multiple values
    -- (for example, \"200,202\") or a range of values (for example,
    -- \"200-299\").
    --
    -- For Gateway Load Balancers, this must be \"200–399\".
    --
    -- Note that when using shorthand syntax, some values such as commas need
    -- to be escaped.
    Matcher -> Maybe Text
httpCode :: Prelude.Maybe Prelude.Text
  }
  deriving (Matcher -> Matcher -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Matcher -> Matcher -> Bool
$c/= :: Matcher -> Matcher -> Bool
== :: Matcher -> Matcher -> Bool
$c== :: Matcher -> Matcher -> Bool
Prelude.Eq, ReadPrec [Matcher]
ReadPrec Matcher
Int -> ReadS Matcher
ReadS [Matcher]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Matcher]
$creadListPrec :: ReadPrec [Matcher]
readPrec :: ReadPrec Matcher
$creadPrec :: ReadPrec Matcher
readList :: ReadS [Matcher]
$creadList :: ReadS [Matcher]
readsPrec :: Int -> ReadS Matcher
$creadsPrec :: Int -> ReadS Matcher
Prelude.Read, Int -> Matcher -> ShowS
[Matcher] -> ShowS
Matcher -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Matcher] -> ShowS
$cshowList :: [Matcher] -> ShowS
show :: Matcher -> String
$cshow :: Matcher -> String
showsPrec :: Int -> Matcher -> ShowS
$cshowsPrec :: Int -> Matcher -> ShowS
Prelude.Show, forall x. Rep Matcher x -> Matcher
forall x. Matcher -> Rep Matcher x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Matcher x -> Matcher
$cfrom :: forall x. Matcher -> Rep Matcher x
Prelude.Generic)

-- |
-- Create a value of 'Matcher' 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:
--
-- 'grpcCode', 'matcher_grpcCode' - You can specify values between 0 and 99. You can specify multiple values
-- (for example, \"0,1\") or a range of values (for example, \"0-5\"). The
-- default value is 12.
--
-- 'httpCode', 'matcher_httpCode' - For Application Load Balancers, you can specify values between 200 and
-- 499, with the default value being 200. You can specify multiple values
-- (for example, \"200,202\") or a range of values (for example,
-- \"200-299\").
--
-- For Network Load Balancers, you can specify values between 200 and 599,
-- with the default value being 200-399. You can specify multiple values
-- (for example, \"200,202\") or a range of values (for example,
-- \"200-299\").
--
-- For Gateway Load Balancers, this must be \"200–399\".
--
-- Note that when using shorthand syntax, some values such as commas need
-- to be escaped.
newMatcher ::
  Matcher
newMatcher :: Matcher
newMatcher =
  Matcher'
    { $sel:grpcCode:Matcher' :: Maybe Text
grpcCode = forall a. Maybe a
Prelude.Nothing,
      $sel:httpCode:Matcher' :: Maybe Text
httpCode = forall a. Maybe a
Prelude.Nothing
    }

-- | You can specify values between 0 and 99. You can specify multiple values
-- (for example, \"0,1\") or a range of values (for example, \"0-5\"). The
-- default value is 12.
matcher_grpcCode :: Lens.Lens' Matcher (Prelude.Maybe Prelude.Text)
matcher_grpcCode :: Lens' Matcher (Maybe Text)
matcher_grpcCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Matcher' {Maybe Text
grpcCode :: Maybe Text
$sel:grpcCode:Matcher' :: Matcher -> Maybe Text
grpcCode} -> Maybe Text
grpcCode) (\s :: Matcher
s@Matcher' {} Maybe Text
a -> Matcher
s {$sel:grpcCode:Matcher' :: Maybe Text
grpcCode = Maybe Text
a} :: Matcher)

-- | For Application Load Balancers, you can specify values between 200 and
-- 499, with the default value being 200. You can specify multiple values
-- (for example, \"200,202\") or a range of values (for example,
-- \"200-299\").
--
-- For Network Load Balancers, you can specify values between 200 and 599,
-- with the default value being 200-399. You can specify multiple values
-- (for example, \"200,202\") or a range of values (for example,
-- \"200-299\").
--
-- For Gateway Load Balancers, this must be \"200–399\".
--
-- Note that when using shorthand syntax, some values such as commas need
-- to be escaped.
matcher_httpCode :: Lens.Lens' Matcher (Prelude.Maybe Prelude.Text)
matcher_httpCode :: Lens' Matcher (Maybe Text)
matcher_httpCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Matcher' {Maybe Text
httpCode :: Maybe Text
$sel:httpCode:Matcher' :: Matcher -> Maybe Text
httpCode} -> Maybe Text
httpCode) (\s :: Matcher
s@Matcher' {} Maybe Text
a -> Matcher
s {$sel:httpCode:Matcher' :: Maybe Text
httpCode = Maybe Text
a} :: Matcher)

instance Data.FromXML Matcher where
  parseXML :: [Node] -> Either String Matcher
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Matcher
Matcher'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"GrpcCode")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"HttpCode")

instance Prelude.Hashable Matcher where
  hashWithSalt :: Int -> Matcher -> Int
hashWithSalt Int
_salt Matcher' {Maybe Text
httpCode :: Maybe Text
grpcCode :: Maybe Text
$sel:httpCode:Matcher' :: Matcher -> Maybe Text
$sel:grpcCode:Matcher' :: Matcher -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
grpcCode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
httpCode

instance Prelude.NFData Matcher where
  rnf :: Matcher -> ()
rnf Matcher' {Maybe Text
httpCode :: Maybe Text
grpcCode :: Maybe Text
$sel:httpCode:Matcher' :: Matcher -> Maybe Text
$sel:grpcCode:Matcher' :: Matcher -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
grpcCode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
httpCode

instance Data.ToQuery Matcher where
  toQuery :: Matcher -> QueryString
toQuery Matcher' {Maybe Text
httpCode :: Maybe Text
grpcCode :: Maybe Text
$sel:httpCode:Matcher' :: Matcher -> Maybe Text
$sel:grpcCode:Matcher' :: Matcher -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"GrpcCode" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
grpcCode,
        ByteString
"HttpCode" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
httpCode
      ]