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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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'
  { -- | For Application Load Balancers, you can specify values between 200 and
    -- 499, and the default value is 200. You can specify multiple values (for
    -- example, \"200,202\") or a range of values (for example, \"200-299\").
    --
    -- For Network Load Balancers and 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,
    -- | 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
  }
  deriving (Matcher -> Matcher -> Bool
(Matcher -> Matcher -> Bool)
-> (Matcher -> Matcher -> Bool) -> Eq Matcher
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]
(Int -> ReadS Matcher)
-> ReadS [Matcher]
-> ReadPrec Matcher
-> ReadPrec [Matcher]
-> Read 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
(Int -> Matcher -> ShowS)
-> (Matcher -> String) -> ([Matcher] -> ShowS) -> Show Matcher
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. Matcher -> Rep Matcher x)
-> (forall x. Rep Matcher x -> Matcher) -> Generic Matcher
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:
--
-- 'httpCode', 'matcher_httpCode' - For Application Load Balancers, you can specify values between 200 and
-- 499, and the default value is 200. You can specify multiple values (for
-- example, \"200,202\") or a range of values (for example, \"200-299\").
--
-- For Network Load Balancers and Gateway Load Balancers, this must be
-- \"200–399\".
--
-- Note that when using shorthand syntax, some values such as commas need
-- to be escaped.
--
-- '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.
newMatcher ::
  Matcher
newMatcher :: Matcher
newMatcher =
  Matcher' :: Maybe Text -> Maybe Text -> Matcher
Matcher'
    { $sel:httpCode:Matcher' :: Maybe Text
httpCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:grpcCode:Matcher' :: Maybe Text
grpcCode = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | For Application Load Balancers, you can specify values between 200 and
-- 499, and the default value is 200. You can specify multiple values (for
-- example, \"200,202\") or a range of values (for example, \"200-299\").
--
-- For Network Load Balancers and 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 :: (Maybe Text -> f (Maybe Text)) -> Matcher -> f Matcher
matcher_httpCode = (Matcher -> Maybe Text)
-> (Matcher -> Maybe Text -> Matcher)
-> Lens Matcher Matcher (Maybe Text) (Maybe Text)
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)

-- | 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 :: (Maybe Text -> f (Maybe Text)) -> Matcher -> f Matcher
matcher_grpcCode = (Matcher -> Maybe Text)
-> (Matcher -> Maybe Text -> Matcher)
-> Lens Matcher Matcher (Maybe Text) (Maybe Text)
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)

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

instance Prelude.Hashable Matcher

instance Prelude.NFData Matcher

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