{-# 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.AppMesh.Types.MatchRange
-- 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.AppMesh.Types.MatchRange 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

-- | An object that represents the range of values to match on. The first
-- character of the range is included in the range, though the last
-- character is not. For example, if the range specified were 1-100, only
-- values 1-99 would be matched.
--
-- /See:/ 'newMatchRange' smart constructor.
data MatchRange = MatchRange'
  { -- | The end of the range.
    MatchRange -> Integer
end :: Prelude.Integer,
    -- | The start of the range.
    MatchRange -> Integer
start :: Prelude.Integer
  }
  deriving (MatchRange -> MatchRange -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MatchRange -> MatchRange -> Bool
$c/= :: MatchRange -> MatchRange -> Bool
== :: MatchRange -> MatchRange -> Bool
$c== :: MatchRange -> MatchRange -> Bool
Prelude.Eq, ReadPrec [MatchRange]
ReadPrec MatchRange
Int -> ReadS MatchRange
ReadS [MatchRange]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MatchRange]
$creadListPrec :: ReadPrec [MatchRange]
readPrec :: ReadPrec MatchRange
$creadPrec :: ReadPrec MatchRange
readList :: ReadS [MatchRange]
$creadList :: ReadS [MatchRange]
readsPrec :: Int -> ReadS MatchRange
$creadsPrec :: Int -> ReadS MatchRange
Prelude.Read, Int -> MatchRange -> ShowS
[MatchRange] -> ShowS
MatchRange -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MatchRange] -> ShowS
$cshowList :: [MatchRange] -> ShowS
show :: MatchRange -> String
$cshow :: MatchRange -> String
showsPrec :: Int -> MatchRange -> ShowS
$cshowsPrec :: Int -> MatchRange -> ShowS
Prelude.Show, forall x. Rep MatchRange x -> MatchRange
forall x. MatchRange -> Rep MatchRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MatchRange x -> MatchRange
$cfrom :: forall x. MatchRange -> Rep MatchRange x
Prelude.Generic)

-- |
-- Create a value of 'MatchRange' 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:
--
-- 'end', 'matchRange_end' - The end of the range.
--
-- 'start', 'matchRange_start' - The start of the range.
newMatchRange ::
  -- | 'end'
  Prelude.Integer ->
  -- | 'start'
  Prelude.Integer ->
  MatchRange
newMatchRange :: Integer -> Integer -> MatchRange
newMatchRange Integer
pEnd_ Integer
pStart_ =
  MatchRange' {$sel:end:MatchRange' :: Integer
end = Integer
pEnd_, $sel:start:MatchRange' :: Integer
start = Integer
pStart_}

-- | The end of the range.
matchRange_end :: Lens.Lens' MatchRange Prelude.Integer
matchRange_end :: Lens' MatchRange Integer
matchRange_end = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MatchRange' {Integer
end :: Integer
$sel:end:MatchRange' :: MatchRange -> Integer
end} -> Integer
end) (\s :: MatchRange
s@MatchRange' {} Integer
a -> MatchRange
s {$sel:end:MatchRange' :: Integer
end = Integer
a} :: MatchRange)

-- | The start of the range.
matchRange_start :: Lens.Lens' MatchRange Prelude.Integer
matchRange_start :: Lens' MatchRange Integer
matchRange_start = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MatchRange' {Integer
start :: Integer
$sel:start:MatchRange' :: MatchRange -> Integer
start} -> Integer
start) (\s :: MatchRange
s@MatchRange' {} Integer
a -> MatchRange
s {$sel:start:MatchRange' :: Integer
start = Integer
a} :: MatchRange)

instance Data.FromJSON MatchRange where
  parseJSON :: Value -> Parser MatchRange
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MatchRange"
      ( \Object
x ->
          Integer -> Integer -> MatchRange
MatchRange'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"end")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"start")
      )

instance Prelude.Hashable MatchRange where
  hashWithSalt :: Int -> MatchRange -> Int
hashWithSalt Int
_salt MatchRange' {Integer
start :: Integer
end :: Integer
$sel:start:MatchRange' :: MatchRange -> Integer
$sel:end:MatchRange' :: MatchRange -> Integer
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Integer
end
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Integer
start

instance Prelude.NFData MatchRange where
  rnf :: MatchRange -> ()
rnf MatchRange' {Integer
start :: Integer
end :: Integer
$sel:start:MatchRange' :: MatchRange -> Integer
$sel:end:MatchRange' :: MatchRange -> Integer
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Integer
end seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Integer
start

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