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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(MatchRange -> MatchRange -> Bool)
-> (MatchRange -> MatchRange -> Bool) -> Eq MatchRange
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]
(Int -> ReadS MatchRange)
-> ReadS [MatchRange]
-> ReadPrec MatchRange
-> ReadPrec [MatchRange]
-> Read 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
(Int -> MatchRange -> ShowS)
-> (MatchRange -> String)
-> ([MatchRange] -> ShowS)
-> Show MatchRange
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. MatchRange -> Rep MatchRange x)
-> (forall x. Rep MatchRange x -> MatchRange) -> Generic MatchRange
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' :: Integer -> Integer -> MatchRange
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 :: (Integer -> f Integer) -> MatchRange -> f MatchRange
matchRange_end = (MatchRange -> Integer)
-> (MatchRange -> Integer -> MatchRange)
-> Lens MatchRange MatchRange Integer Integer
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 :: (Integer -> f Integer) -> MatchRange -> f MatchRange
matchRange_start = (MatchRange -> Integer)
-> (MatchRange -> Integer -> MatchRange)
-> Lens MatchRange MatchRange Integer Integer
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 Core.FromJSON MatchRange where
  parseJSON :: Value -> Parser MatchRange
parseJSON =
    String
-> (Object -> Parser MatchRange) -> Value -> Parser MatchRange
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MatchRange"
      ( \Object
x ->
          Integer -> Integer -> MatchRange
MatchRange'
            (Integer -> Integer -> MatchRange)
-> Parser Integer -> Parser (Integer -> MatchRange)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Integer
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"end") Parser (Integer -> MatchRange)
-> Parser Integer -> Parser MatchRange
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Integer
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"start")
      )

instance Prelude.Hashable MatchRange

instance Prelude.NFData MatchRange

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"end" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Integer
end),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"start" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Integer
start)
          ]
      )